Class: Forerunner::ActionData

Inherits:
Object
  • Object
show all
Defined in:
lib/forerunner/action_data.rb,
lib/forerunner/action_data/invalid_action_type_error.rb,
lib/forerunner/action_data/missing_action_name_error.rb

Defined Under Namespace

Classes: InvalidActionTypeError, MissingActionNameError

Constant Summary collapse

VALID_ACTION_TYPES =
%i(before around after)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_type:, action_data:, block: nil) ⇒ ActionData

Returns a new instance of ActionData.



7
8
9
10
11
12
13
14
15
# File 'lib/forerunner/action_data.rb', line 7

def initialize(action_type:, action_data:, block: nil)
  @action_type = action_type
  @options = action_data.extract_options!
  @action_names = action_data
  @block = block

  validate_action_type!
  validate_action_names!
end

Instance Attribute Details

#action_namesObject (readonly)

Returns the value of attribute action_names.



5
6
7
# File 'lib/forerunner/action_data.rb', line 5

def action_names
  @action_names
end

#action_typeObject (readonly)

Returns the value of attribute action_type.



5
6
7
# File 'lib/forerunner/action_data.rb', line 5

def action_type
  @action_type
end

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/forerunner/action_data.rb', line 5

def block
  @block
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/forerunner/action_data.rb', line 5

def options
  @options
end

Instance Method Details

#limit_to_action(action) ⇒ Object



17
18
19
# File 'lib/forerunner/action_data.rb', line 17

def limit_to_action(action)
  options[:only] = [action]
end

#paramsObject



21
22
23
# File 'lib/forerunner/action_data.rb', line 21

def params
  action_names + [options]
end