Class: Julia::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/julia/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, action = nil, &block) ⇒ Action

Returns a new instance of Action.



5
6
7
8
9
# File 'lib/julia/action.rb', line 5

def initialize(key, action = nil, &block)
  @key    = key
  @action = action
  @block  = block
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/julia/action.rb', line 3

def action
  @action
end

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/julia/action.rb', line 3

def block
  @block
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/julia/action.rb', line 3

def key
  @key
end

Instance Method Details

#get_value(record) ⇒ Object



11
12
13
14
15
16
# File 'lib/julia/action.rb', line 11

def get_value(record)
  return block.call(record) if block
  return record.instance_exec(&action) if action.is_a? Proc

  record.send [action, key].compact.first
end