Class: Logux::Action

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/logux/action.rb

Direct Known Subclasses

Actions

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ Action

Returns a new instance of Action.

Raises:

  • (ArgumentError)


23
24
25
26
27
# File 'lib/logux/action.rb', line 23

def initialize(parameters = {})
  raise ArgumentError, :parameters unless parameters.is_a?(Hash)

  @parameters = parameters.transform_keys(&:to_s)
end

Instance Method Details

#[](key) ⇒ Object



60
61
62
# File 'lib/logux/action.rb', line 60

def [](key)
  parameters[key.is_a?(Symbol) ? key.to_s : key]
end

#action_nameObject



29
30
31
# File 'lib/logux/action.rb', line 29

def action_name
  type&.split('/')&.dig(0)
end

#action_typeObject



33
34
35
# File 'lib/logux/action.rb', line 33

def action_type
  type&.split('/')&.last
end

#channelObject



49
50
51
# File 'lib/logux/action.rb', line 49

def channel
  fetch('channel')
end

#channel_idObject



41
42
43
# File 'lib/logux/action.rb', line 41

def channel_id
  channel&.split('/')&.last
end

#channel_nameObject



37
38
39
# File 'lib/logux/action.rb', line 37

def channel_name
  channel&.split('/')&.dig(0)
end

#fetch(key) ⇒ Object



53
54
55
56
57
58
# File 'lib/logux/action.rb', line 53

def fetch(key)
  value = self[key]
  raise ParameterMissingError, key if value.to_s.empty?

  value
end

#typeObject



45
46
47
# File 'lib/logux/action.rb', line 45

def type
  fetch('type')
end