Class: Fib::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/fib/element.rb

Constant Summary collapse

TYPE =
%w(key action url).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, core, condition = ->(*args){}) ⇒ Element

Returns a new instance of Element.

Raises:



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

#conditionObject (readonly)

Returns the value of attribute condition.



3
4
5
# File 'lib/fib/element.rb', line 3

def condition
  @condition
end

#coreObject (readonly)

Returns the value of attribute core.



3
4
5
# File 'lib/fib/element.rb', line 3

def core
  @core
end

#permission_keyObject (readonly)

Returns the value of attribute permission_key.



3
4
5
# File 'lib/fib/element.rb', line 3

def permission_key
  @permission_key
end

#typeObject (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

Returns:

  • (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 set_permission permission
  @permission_key = permission.is_a?(Fib::Permission) ? permission.key : permission
end