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.



195
196
197
# File 'lib/hyper-operation/transport/policy.rb', line 195

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



173
174
175
# File 'lib/hyper-operation/transport/policy.rb', line 173

def klass
  @klass
end

Class Method Details

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



137
138
139
140
141
142
# File 'lib/hyper-operation/transport/policy.rb', line 137

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

.allowed_optsObject



167
168
169
# File 'lib/hyper-operation/transport/policy.rb', line 167

def allowed_opts
  []
end

.regulationsObject



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/hyper-operation/transport/policy.rb', line 144

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



156
157
158
159
160
161
162
163
164
165
# File 'lib/hyper-operation/transport/policy.rb', line 156

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)


191
192
193
# File 'lib/hyper-operation/transport/policy.rb', line 191

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

#optsObject



175
176
177
# File 'lib/hyper-operation/transport/policy.rb', line 175

def opts
  @opts ||= {}
end

#regulate_for(acting_user) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/hyper-operation/transport/policy.rb', line 183

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

#regulationsObject



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

def regulations
  @regulations ||= []
end