Class: Hyperloop::ClassConnectionRegulation

Inherits:
Regulation
  • Object
show all
Defined in:
lib/hyper-operation/transport/policy.rb

Instance Attribute Summary

Attributes inherited from Regulation

#klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Regulation

#auto_connect_disabled?, #initialize, #opts, #regulate_for, #regulations, regulations, wrap_policy

Constructor Details

This class inherits a constructor from Hyperloop::Regulation

Class Method Details

.add_regulation(klass, opts = {}, &regulation) ⇒ Object


245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/hyper-operation/transport/policy.rb', line 245

def self.add_regulation(klass, opts={}, &regulation)
  actual_klass = if klass.is_a?(Class)
                   klass
                 else
                   begin
                     klass.constantize
                   rescue NameError
                     nil
                   end
                 end
  if actual_klass && actual_klass.respond_to?(:dispatch_to)
    begin
      actual_klass.dispatch_to(actual_klass)
    rescue NoMethodError
      # this is the case for ClassPolicy where the instance method :dispatch_to has been deleted.
      nil
    end
  end
  super
end

.allowed_optsObject


282
283
284
# File 'lib/hyper-operation/transport/policy.rb', line 282

def self.allowed_opts
  [:auto_connect]
end

.connect(channel, acting_user) ⇒ Object


270
271
272
# File 'lib/hyper-operation/transport/policy.rb', line 270

def self.connect(channel, acting_user)
  raise "connection failed" unless regulations[channel].connectable?(acting_user)
end

.connections_for(acting_user, auto_connections_only) ⇒ Object


274
275
276
277
278
279
280
# File 'lib/hyper-operation/transport/policy.rb', line 274

def self.connections_for(acting_user, auto_connections_only)
  regulations.collect do |channel, regulation|
    next if auto_connections_only && regulation.auto_connect_disabled?
    next if !regulation.connectable?(acting_user)
    channel
  end.compact
end

Instance Method Details

#connectable?(acting_user) ⇒ Boolean

Returns:

  • (Boolean)

266
267
268
# File 'lib/hyper-operation/transport/policy.rb', line 266

def connectable?(acting_user)
  regulate_for(acting_user).all? unless regulations.empty? rescue nil
end