Class: Hyperloop::Regulation

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Regulation

Returns a new instance of Regulation.



237
238
239
# File 'lib/hyper-operation/transport/policy.rb', line 237

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



215
216
217
# File 'lib/hyper-operation/transport/policy.rb', line 215

def klass
  @klass
end

Class Method Details

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



179
180
181
182
183
184
# File 'lib/hyper-operation/transport/policy.rb', line 179

def add_regulation(klass, opts={}, &regulation)
  klass = regulations[klass]
  klass.opts.merge! opts
  klass.regulations << regulation
  klass
end

.allowed_optsObject



209
210
211
# File 'lib/hyper-operation/transport/policy.rb', line 209

def allowed_opts
  []
end

.regulationsObject



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/hyper-operation/transport/policy.rb', line 186

def regulations
  @regulations ||= Hash.new do |hash, klass|
    if klass.is_a? String
      hash[klass] = new(klass)
    elsif klass.is_a?(Class) && klass.name
      hash[klass.name]
    else
      hash[klass.class.name]
    end
  end
end

.wrap_policy(policy, regulation) ⇒ Object



198
199
200
201
202
203
204
205
206
207
# File 'lib/hyper-operation/transport/policy.rb', line 198

def wrap_policy(policy, regulation)
  begin
    policy_klass = regulation.binding.receiver
  rescue
    raise "Could not determine the class when regulating.  This is probably caused by doing something like &:send_all"
  end
  wrapped_policy = policy_klass.new(nil, nil)
  wrapped_policy.hyperloop_internal_policy_object = policy
  wrapped_policy
end

Instance Method Details

#auto_connect_disabled?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/hyper-operation/transport/policy.rb', line 233

def auto_connect_disabled?
  opts.has_key?(:auto_connect) && !opts[:auto_connect]
end

#optsObject



217
218
219
# File 'lib/hyper-operation/transport/policy.rb', line 217

def opts
  @opts ||= {}
end

#regulate_for(acting_user) ⇒ Object



225
226
227
228
229
230
231
# File 'lib/hyper-operation/transport/policy.rb', line 225

def regulate_for(acting_user)
  Enumerator.new do |y|
    regulations.each do |regulation|
      y << acting_user.instance_eval(&regulation)
    end
  end
end

#regulationsObject



221
222
223
# File 'lib/hyper-operation/transport/policy.rb', line 221

def regulations
  @regulations ||= []
end