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

Commit f4f23ab

Browse files
committed
Merge branch 'master' into no_call_by_class_name
2 parents a27b3fc + a9e8a91 commit f4f23ab

File tree

9 files changed

+61
-101
lines changed

9 files changed

+61
-101
lines changed

lib/hyper-operation/railway/validations.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def add_error(param, symbol, message, *args, &block)
2424
add_validation do
2525
begin
2626
add_error(param, symbol, message) if instance_eval(&block)
27+
true
2728
rescue Exit => e
2829
raise e unless e.state == :failed
2930
add_error(param, symbol, message)

lib/hyper-operation/server_op.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ def run(*args)
1717
end
1818
end if RUBY_ENGINE == 'opal'
1919

20-
def run_from_client(security_param, operation, params)
20+
def run_from_client(security_param, controller, operation, params)
2121
operation.constantize.class_eval do
22-
raise AccessViolation unless _Railway.params_wrapper.method_defined? security_param
22+
if _Railway.params_wrapper.method_defined?(:controller)
23+
params[:controller] = controller
24+
elsif !_Railway.params_wrapper.method_defined?(security_param)
25+
raise AccessViolation
26+
end
2327
run(params)
2428
.then { |r| return { json: { response: serialize_response(r) } } }
25-
.fail { |e| return { json: { error: e}, status: 500 } }
29+
.fail { |e| return { json: { error: e }, status: 500 } }
2630
end
2731
rescue Exception => e
2832
{ json: {error: e}, status: 500 }
@@ -95,4 +99,16 @@ def dispatch_from_server(params_hash)
9599
end
96100
end
97101
end
102+
103+
class ControllerOp < ServerOp
104+
param :controller
105+
alias pre_controller_op_method_missing method_missing
106+
def method_missing(name, *args, &block)
107+
if params.controller.respond_to? name
108+
params.controller.send(name, *args, &block)
109+
else
110+
pre_controller_op_method_missing(name, *args, &block)
111+
end
112+
end
113+
end
98114
end

lib/hyper-operation/transport/client_drivers.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def self.sync_dispatch(data)
121121
client_logging: Hyperloop.client_logging,
122122
pusher_fake_js: pusher_fake_js,
123123
key: Hyperloop.key,
124+
cluster: Hyperloop.cluster,
124125
encrypted: Hyperloop.encrypted,
125126
channel: Hyperloop.channel,
126127
form_authenticity_token: controller.send(:form_authenticity_token),
@@ -153,6 +154,18 @@ def self.get_queued_data(operation, channel = nil, opts = {})
153154

154155
def self.initialize_client_drivers_on_boot
155156

157+
if @initialized
158+
# 1) skip initialization if already initialized
159+
# 2) if running action_cable make sure connection is up after pinging the server_up
160+
# action cable closes the connection if files change on the server
161+
HTTP.get("#{`window.HyperloopEnginePath`}/server_up") do
162+
`#{Hyperloop.action_cable_consumer}.connection.open()` if `#{Hyperloop.action_cable_consumer}.connection.disconnected`
163+
end if Hyperloop.action_cable_consumer
164+
return
165+
end
166+
167+
@initialized = true
168+
156169
if RUBY_ENGINE == 'opal'
157170
@opts = Hash.new(`window.HyperloopOpts`)
158171
end
@@ -176,6 +189,7 @@ def self.initialize_client_drivers_on_boot
176189
%x{
177190
h = {
178191
encrypted: #{opts[:encrypted]},
192+
cluster: #{opts[:cluster]},
179193
authEndpoint: window.HyperloopEnginePath+'/hyperloop-pusher-auth',
180194
auth: {headers: {'X-CSRF-Token': #{opts[:form_authenticity_token]}}}
181195
};

lib/hyper-operation/transport/hyperloop.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ def self.secret
7474
opts[:secret] || Pusher.secret if transport == :pusher
7575
end
7676

77+
def self.cluster
78+
# mt1 is the default Pusher app cluster
79+
opts[:cluster] || 'mt1' if transport == :pusher
80+
end
81+
7782
def self.encrypted
7883
opts.key?(:encrypted) ? opts[:encrypted] : true
7984
end
@@ -125,7 +130,7 @@ def self.pusher
125130
raise '******** NO CHANNEL PREFIX SET ***************'
126131
end
127132
@pusher = Pusher::Client.new(
128-
opts || { app_id: app_id, key: key, secret: secret }
133+
opts || { app_id: app_id, key: key, secret: secret, cluster: cluster }
129134
)
130135
end
131136
@pusher

lib/hyper-operation/transport/hyperloop_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,18 @@ def connect_to_transport
131131
def execute_remote
132132
parsed_params = JSON.parse(params[:json]).symbolize_keys
133133
render ServerOp.run_from_client(
134-
:acting_user, parsed_params[:operation], parsed_params[:params].merge(acting_user: acting_user))
134+
:acting_user,
135+
self,
136+
parsed_params[:operation],
137+
parsed_params[:params].merge(acting_user: acting_user)
138+
)
135139
end
136140

137141
def execute_remote_api
138-
parsed_params = params[:params].symbolize_keys
142+
params.require(:params).permit!
143+
parsed_params = params[:params].to_h.symbolize_keys
139144
raise AccessViolation unless parsed_params[:authorization]
140-
render ServerOp.run_from_client(:authorization, params[:operation], parsed_params)
145+
render ServerOp.run_from_client(:authorization, self, params[:operation], parsed_params)
141146
end
142147

143148
def console_update # TODO this should just become an execute-remote-api call

lib/hyper-operation/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Hyperloop
22
class Operation
3-
VERSION = '0.5.7'
3+
VERSION = '0.5.12'
44
end
55
end

0 commit comments

Comments
 (0)