Class: Fib::Element
- Inherits:
-
Object
- Object
- Fib::Element
- Defined in:
- lib/fib/element.rb
Constant Summary collapse
- TYPE =
%w(key action url).freeze
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#permission_key ⇒ Object
readonly
Returns the value of attribute permission_key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .create_action(controller, action, &block) ⇒ Object
- .create_key(key, &block) ⇒ Object
- .create_url(url, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(type, core, condition = ->(*args){}) ⇒ Element
constructor
A new instance of Element.
- #pass_condition?(*args) ⇒ Boolean
- #set_permission(permission) ⇒ Object
Constructor Details
#initialize(type, core, condition = ->(*args){}) ⇒ Element
Returns a new instance of Element.
6 7 8 9 10 11 12 |
# File 'lib/fib/element.rb', line 6 def initialize type, core, condition=->(*args){} raise UnValidElementType, "current type -> #{type}, type need in (#{TYPE.join(", ")})!" unless TYPE.include? type @type = type @core = core raise ParameterIsNotValid, "Condition must belong to Proc!" unless condition.nil? || condition.is_a?(Proc) @condition = condition || ->(*args){} end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
3 4 5 |
# File 'lib/fib/element.rb', line 3 def condition @condition end |
#core ⇒ Object (readonly)
Returns the value of attribute core.
3 4 5 |
# File 'lib/fib/element.rb', line 3 def core @core end |
#permission_key ⇒ Object (readonly)
Returns the value of attribute permission_key.
3 4 5 |
# File 'lib/fib/element.rb', line 3 def @permission_key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/fib/element.rb', line 3 def type @type end |
Class Method Details
.create_action(controller, action, &block) ⇒ Object
28 29 30 |
# File 'lib/fib/element.rb', line 28 def create_action controller, action, &block new "action", {controller: controller.to_s, action: action.to_s}, block end |
.create_key(key, &block) ⇒ Object
24 25 26 |
# File 'lib/fib/element.rb', line 24 def create_key key, &block new "key", key, block end |
.create_url(url, &block) ⇒ Object
32 33 34 |
# File 'lib/fib/element.rb', line 32 def create_url url, &block new "url", url, block end |
Instance Method Details
#pass_condition?(*args) ⇒ Boolean
18 19 20 21 |
# File 'lib/fib/element.rb', line 18 def pass_condition? *args return true if condition.nil? condition[*args] != false end |
#set_permission(permission) ⇒ Object
14 15 16 |
# File 'lib/fib/element.rb', line 14 def @permission_key = .is_a?(Fib::Permission) ? .key : end |