Method: Injectable::ClassMethods#argument

Defined in:
lib/injectable/class_methods.rb

#argument(name, options = {}) ⇒ Object

Declare the arguments for ‘#call` and initialize the accessors This helps us clean up the code for memoization:

“‘ private

def player

# player_id exists in the context because we added it as an argument
@player ||= player_query.call(player_id)

end “‘

Every argument is required unless given an optional default value

Examples:

argument :player_id
  # => def call(player_id:)
  # =>   @player_id = player_id
  # => end

with default arguments

argument :team_id, default: 1
  # => def call(team_id: 1)
  # =>   @team_id = team_id
  # => end

Parameters:

  • name

    Name of the argument

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :default (Object)

    The default value of the argument



133
134
135
136
# File 'lib/injectable/class_methods.rb', line 133

def argument(name, options = {})
  call_arguments[name] = options
  attr_accessor name
end