Class: Platanus::Canned2::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/platanus/canned2.rb

Overview

Holds all rules associated to a single user profile.

This class describes the avaliable DSL when defining a new profile. TODO: example

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_base, _def_matcher, _def_resource) ⇒ Profile

The initializer takes another profile as rules base.



102
103
104
105
106
107
108
# File 'lib/platanus/canned2.rb', line 102

def initialize(_base, _def_matcher, _def_resource)
  @rules = Hash.new { |h, k| h[k] = [] }
  _base.rules.each { |k, tests| @rules[k] = tests.clone } unless _base.nil?
  raise Error.new 'Must provide a default test' if _def_matcher.nil?
  @def_matcher = _def_matcher
  @def_resource = _def_resource
end

Instance Attribute Details

#def_matcherObject (readonly)

Returns the value of attribute def_matcher.



98
99
100
# File 'lib/platanus/canned2.rb', line 98

def def_matcher
  @def_matcher
end

#def_resourceObject (readonly)

Returns the value of attribute def_resource.



99
100
101
# File 'lib/platanus/canned2.rb', line 99

def def_resource
  @def_resource
end

#rulesObject (readonly)

Returns the value of attribute rules.



97
98
99
# File 'lib/platanus/canned2.rb', line 97

def rules
  @rules
end

Instance Method Details

#allow(_action, _upon = nil, &_block) ⇒ Object

 Adds an “allowance” rule



111
112
113
# File 'lib/platanus/canned2.rb', line 111

def allow(_action, _upon=nil, &_block)
  @rules[_action] << (_upon || _block)
end

#clear(_action) ⇒ Object

Clear all rules related to an action



121
122
123
# File 'lib/platanus/canned2.rb', line 121

def clear(_action)
  @rules[_action] = []
end

#forbid(_action) ⇒ Object

Adds a “forbidden” rule



116
117
118
# File 'lib/platanus/canned2.rb', line 116

def forbid(_action)
  # TODO
end

#upon(_expr = nil, &_block) ⇒ Object

SHORT HAND METHODS



127
128
129
# File 'lib/platanus/canned2.rb', line 127

def upon(_expr=nil, &_block)
  Proc.new { upon(_expr, &_block) }
end

#upon_all(_expr, &_block) ⇒ Object



135
136
137
# File 'lib/platanus/canned2.rb', line 135

def upon_all(_expr, &_block)
  Proc.new { upon_all(_expr, &_block) }
end

#upon_one(_expr, &_block) ⇒ Object



131
132
133
# File 'lib/platanus/canned2.rb', line 131

def upon_one(_expr, &_block)
  Proc.new { upon_one(_expr, &_block) }
end