Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 366c6cc

Browse files
committed
initial commit - not working for some reason
1 parent a9e8a91 commit 366c6cc

18 files changed

+394
-57
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ Your Isomorphic Operations live in a `app/hyperloop/operations` folder and your
101101

102102
You will also find an `app/policies` folder with a simple access policy suited for development. Policies are how you will provide detailed access control to your Isomorphic models.
103103

104+
## Developing and Testing
105+
106+
`git clone` the project.
107+
108+
setup the environment
109+
`bundle install`
110+
`cd spec/test_app`
111+
`bundle install`
112+
`bundle exec rake db:create`
113+
`cd ../..`
114+
115+
run the tests
116+
`bundle exec rake`
117+
118+
client side tests will run normally in the headless poltergeist browser environment. To see what is going on say
119+
`DRIVER=ff bundle exec rake`
120+
104121
## Contributing
105122

106123
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-hyperloop/hyper-operation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Code of Conduct](https://github.com/ruby-hyperloop/hyper-operation/blob/master/CODE_OF_CONDUCT.md) code of conduct.

hyper-operation.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Gem::Specification.new do |spec|
2323
spec.add_dependency 'hyperloop-config', '>= 0.9.7'
2424
spec.add_dependency 'opal-activesupport'
2525
spec.add_dependency 'activerecord', '>= 0.3.0'
26-
spec.add_dependency 'pusher'
27-
spec.add_dependency 'pusher-fake'
2826

2927
spec.add_development_dependency "bundler", "~> 1.8"
3028
spec.add_development_dependency "rake", "~> 10.0"
@@ -35,10 +33,13 @@ Gem::Specification.new do |spec|
3533
spec.add_development_dependency 'hyper-react'
3634
spec.add_development_dependency 'opal-browser'
3735
spec.add_development_dependency 'sqlite3', '1.3.10'
36+
spec.add_development_dependency 'mysql2'
3837
spec.add_development_dependency 'database_cleaner'
3938
spec.add_development_dependency 'pry'
4039
spec.add_development_dependency 'rspec-wait'
4140
spec.add_development_dependency 'puma'
4241
spec.add_development_dependency 'rspec-steps'
42+
spec.add_development_dependency 'pusher'
43+
spec.add_development_dependency 'pusher-fake'
4344

4445
end

lib/hyper-operation/api.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def param(*args, &block)
6363
_Railway.add_param(*args, &block)
6464
end
6565

66+
def inbound(*args, &block)
67+
name, opts = ParamsWrapper.get_name_and_opts(*args)
68+
_Railway.add_param(name, opts.merge(inbound: :true), &block)
69+
end
70+
6671
def outbound(*keys)
6772
keys.each { |key| _Railway.add_param(key => nil, :type => :outbound) }
6873
#singleton_class.outbound(*keys)
@@ -102,6 +107,11 @@ def inherited(child)
102107
_Railway.add_param(*args, &block)
103108
end
104109

110+
child.singleton_class.define_singleton_method(:inbound) do |*args, &block|
111+
name, opts = ParamsWrapper.get_name_and_opts(*args)
112+
_Railway.add_param(name, opts.merge(inbound: :true), &block)
113+
end
114+
105115
child.singleton_class.define_singleton_method(:outbound) do |*keys|
106116
keys.each { |key| _Railway.add_param(key => nil, :type => :outbound) }
107117
end

lib/hyper-operation/railway/params_wrapper.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ def lock
1212
end
1313

1414
def to_h
15-
@inputs.with_indifferent_access
15+
inputs = @inputs
16+
if @locked
17+
inputs = inputs.dup
18+
self.class.inbound_params.each { |name| inputs.delete :"#{name}" }
19+
end
20+
inputs.with_indifferent_access
1621
end
1722

1823
def to_s
@@ -39,6 +44,7 @@ def process_params(operation, args)
3944

4045
def add_param(*args, &block)
4146
type_method, name, opts, block = translate_args(*args, &block)
47+
inbound_params << :"#{name}" if opts.delete(:inbound)
4248
if opts.key? :default
4349
hash_filter.optional { send(type_method, name, opts, &block) }
4450
else
@@ -65,6 +71,10 @@ def hash_filter
6571
@hash_filter ||= Mutations::HashFilter.new
6672
end
6773

74+
def inbound_params
75+
@inbound_params ||= Set.new
76+
end
77+
6878
def translate_args(*args, &block)
6979
name, opts = get_name_and_opts(*args)
7080
if opts.key?(:type)
@@ -115,6 +125,8 @@ def self.params_wrapper
115125
Class.new(superclass.params_wrapper).tap do |wrapper|
116126
hash_filter = superclass.params_wrapper.hash_filter
117127
wrapper.instance_variable_set('@hash_filter', hash_filter && hash_filter.dup)
128+
inbound_params = superclass.params_wrapper.inbound_params
129+
wrapper.instance_variable_set('@inbound_params', inbound_params && inbound_params.dup)
118130
end
119131
end
120132
end

lib/hyper-operation/server_op.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def dispatch_from_server(params_hash)
101101
end
102102

103103
class ControllerOp < ServerOp
104-
param :controller
104+
inbound :controller
105105
alias pre_controller_op_method_missing method_missing
106106
def method_missing(name, *args, &block)
107107
if params.controller.respond_to? name

lib/hyper-operation/transport/client_drivers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def self.connect(*channels)
2828
end
2929
end
3030

31+
def self.connect_session
32+
connect(['Hyperloop::Session', ClientDrivers.opts[:id].split('-').last])
33+
end
34+
3135
def self.action_cable_consumer
3236
ClientDrivers.opts[:action_cable_consumer]
3337
end
@@ -114,6 +118,7 @@ def self.sync_dispatch(data)
114118
end
115119
controller.session.delete 'hyperloop-dummy-init' unless controller.session.id
116120
id = "#{SecureRandom.uuid}-#{controller.session.id}"
121+
auto_connections = Hyperloop::AutoConnect.channels(id, controller.acting_user)
117122
config_hash = {
118123
transport: Hyperloop.transport,
119124
id: id,
@@ -126,7 +131,7 @@ def self.sync_dispatch(data)
126131
channel: Hyperloop.channel,
127132
form_authenticity_token: controller.send(:form_authenticity_token),
128133
seconds_between_poll: Hyperloop.seconds_between_poll,
129-
auto_connect: Hyperloop::AutoConnect.channels(id, controller.acting_user)
134+
auto_connect: auto_connections
130135
}
131136
path = ::Rails.application.routes.routes.detect do |route|
132137
# not sure why the second check is needed. It happens in the test app
@@ -171,7 +176,6 @@ def self.initialize_client_drivers_on_boot
171176
end
172177

173178
if on_opal_client?
174-
175179
if opts[:transport] == :pusher
176180

177181
opts[:dispatch] = lambda do |data|

lib/hyper-operation/transport/hyperloop.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def self.reset_operations
1919
config.after_initialize { Connection.build_tables }
2020
end
2121
Object.send(:remove_const, :Application) if @fake_application_defined
22+
@fake_application_defined = false
2223
policy = begin
2324
Object.const_get 'ApplicationPolicy'
2425
rescue LoadError
@@ -61,6 +62,7 @@ def self.reset_operations
6162
define_setting :opts, {}
6263
define_setting :channel_prefix, 'synchromesh'
6364
define_setting :client_logging, true
65+
define_setting :connect_session, true
6466

6567
def self.app_id
6668
opts[:app_id] || Pusher.app_id if transport == :pusher

lib/hyper-operation/transport/hyperloop_controller.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ def client_id
4242
session.delete 'hyperloop-dummy-init' unless session.id
4343
end
4444

45+
def session_channel
46+
"Hyperloop::Session-#{session.id}"
47+
end
48+
49+
def regulate(channel)
50+
unless channel == session_channel # "Hyperloop::Session-#{client_id.split('-').last}"
51+
Hyperloop::InternalPolicy.regulate_connection(try(:acting_user), channel)
52+
end
53+
channel
54+
end
55+
4556
def channels(user = acting_user, session_id = session.id)
4657
Hyperloop::AutoConnect.channels(session_id, user)
4758
end
@@ -89,8 +100,7 @@ def debug_console
89100
end
90101

91102
def subscribe
92-
channel = params[:channel].gsub('==', '::')
93-
Hyperloop::InternalPolicy.regulate_connection(try(:acting_user), channel)
103+
channel = regulate params[:channel].gsub('==', '::')
94104
root_path = request.original_url.gsub(/hyperloop-subscribe.*$/, '')
95105
Hyperloop::Connection.open(channel, client_id, root_path)
96106
head :ok
@@ -105,17 +115,15 @@ def read
105115
end
106116

107117
def pusher_auth
108-
channel = params[:channel_name].gsub(/^#{Regexp.quote(Hyperloop.channel)}\-/,'').gsub('==', '::')
109-
Hyperloop::InternalPolicy.regulate_connection(acting_user, channel)
118+
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(Hyperloop.channel)}\-/,'').gsub('==', '::')
110119
response = Hyperloop.pusher.authenticate(params[:channel_name], params[:socket_id])
111120
render json: response
112121
rescue Exception => e
113122
head :unauthorized
114123
end
115124

116125
def action_cable_auth
117-
channel = params[:channel_name].gsub(/^#{Regexp.quote(Hyperloop.channel)}\-/,'')
118-
Hyperloop::InternalPolicy.regulate_connection(acting_user, channel)
126+
channel = regulate params[:channel_name].gsub(/^#{Regexp.quote(Hyperloop.channel)}\-/,'')
119127
salt = SecureRandom.hex
120128
authorization = Hyperloop.authorization(salt, channel, client_id)
121129
render json: {authorization: authorization, salt: salt}

lib/hyper-operation/transport/policy.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,8 @@ module AutoConnect
296296
def self.channels(session, acting_user)
297297
channels = ClassConnectionRegulation.connections_for(acting_user, true) +
298298
InstanceConnectionRegulation.connections_for(acting_user, true)
299-
channels = channels.uniq
300-
channels.each do |channel|
301-
Connection.open(channel, session)
302-
end
303-
channels
299+
channels << "Hyperloop::Session-#{session.split('-').last}" if Hyperloop.connect_session && session
300+
channels.uniq.each { |channel| Connection.open(channel, session) }
304301
end
305302
end
306303

spec/hyper-operation/basics_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ def self.inherited(child)
145145
expect(MyOperation.run(sku: "sku", qty: 4)).to be_resolved
146146
end
147147

148+
it "can have inbound params" do
149+
MyOperation.inbound :inbounder
150+
MyOperation.outbound :outbounder
151+
MyOperation.step { params.outbounder = params.inbounder }
152+
expect(Store).to receive(:receiver).with({outbounder: 'hello'})
153+
expect(MyOperation.run(inbounder: 'hello')).to be_resolved
154+
end
155+
148156
it "params cannot be updated in a reciever" do
149157
MyOperation.param :sku, type: String
150158
Store.class_eval do

0 commit comments

Comments
 (0)