Module: ActiveInteractor::Context::Attributes::ClassMethods

Included in:
Base
Defined in:
lib/active_interactor/context/attributes.rb

Overview

Context attribute class methods. Because ClassMethods is a module classes should extend ClassMethods rather than inherit from it.

Since:

  • 0.1.4

Instance Method Summary collapse

Instance Method Details

#attributes(*attributes) ⇒ Array<Symbol>

Get or set attributes on a context class

Examples:

Set attributes on a context class

class MyContext < ActiveInteractor::Context::Base
  attributes :first_name, :last_name
end

Get attributes defined on a context class

MyContext.attributes
#=> [:first_name, :last_name]

Returns:

  • (Array<Symbol>)

    the defined attributes

Since:

  • 0.1.4



29
30
31
32
33
# File 'lib/active_interactor/context/attributes.rb', line 29

def attributes(*attributes)
  return __attributes if attributes.empty?

  @__attributes = __attributes.concat(attributes.map(&:to_sym)).compact.uniq.sort
end