module ActiveInteractor::Context::Attributes::ClassMethods

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

@author Aaron Allen <hello@aaronmallen.me> @since 0.1.4

Public Instance Methods

attributes(*attributes) click to toggle source

Get or set attributes on a {Base context} class

@example Set attributes on a {Base context} class

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

@example Get attributes defined on a {Base context} class

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

@example Set defaults for attributes on a {Base context} class

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

@return [Array<Symbol>] the defined attributes

# 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

Private Instance Methods

attribute?(attr_name) click to toggle source
# File lib/active_interactor/context/attributes.rb, line 42
def attribute?(attr_name)
  attribute_types.key?(attr_name.to_s)
end
Also aliased as: has_attribute?
has_attribute?(attr_name)
Alias for: attribute?