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.

Author:

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]

Set defaults for attributes on a context class

class MyContext < ActiveInteractor::Context::Base
  attributes first_name: { default: -> { 'Aaron' } }, last_name: { default: -> { 'Allen' } }
end

Returns:

  • (Array<Symbol>)

    the defined attributes

Since:

  • 0.1.4



34
35
36
37
38
# File 'lib/active_interactor/context/attributes.rb', line 34

def attributes(*attributes)
  attributes.compact.uniq.each { |attr| attribute(attr) }

  attribute_names.sort.collect(&:to_sym)
end