Class: HyperMesh::Regulation
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(klass) ⇒ Regulation
Returns a new instance of Regulation.
171
172
173
|
# File 'lib/synchromesh/policy.rb', line 171
def initialize(klass)
@klass = klass
end
|
Instance Attribute Details
Returns the value of attribute klass.
149
150
151
|
# File 'lib/synchromesh/policy.rb', line 149
def klass
@klass
end
|
Class Method Details
.add_regulation(klass, opts = {}, ®ulation) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/synchromesh/policy.rb', line 113
def add_regulation(klass, opts={}, ®ulation)
klass = regulations[klass]
klass.opts.merge! opts
klass.regulations << regulation
klass
end
|
.allowed_opts ⇒ Object
143
144
145
|
# File 'lib/synchromesh/policy.rb', line 143
def allowed_opts
[]
end
|
.regulations ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/synchromesh/policy.rb', line 120
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
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/synchromesh/policy.rb', line 132
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.synchromesh_internal_policy_object = policy
wrapped_policy
end
|
Instance Method Details
#auto_connect_disabled? ⇒ Boolean
167
168
169
|
# File 'lib/synchromesh/policy.rb', line 167
def auto_connect_disabled?
opts.has_key?(:auto_connect) && !opts[:auto_connect]
end
|
151
152
153
|
# File 'lib/synchromesh/policy.rb', line 151
def opts
@opts ||= {}
end
|
#regulate_for(acting_user) ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/synchromesh/policy.rb', line 159
def regulate_for(acting_user)
Enumerator.new do |y|
regulations.each do |regulation|
y << acting_user.instance_eval(®ulation)
end
end
end
|
#regulations ⇒ Object
155
156
157
|
# File 'lib/synchromesh/policy.rb', line 155
def regulations
@regulations ||= []
end
|