Module: Shamu::Attributes::Assignment

Extended by:
ActiveSupport::Concern
Included in:
Entities::ListScope, JsonApi::Rails::Pagination, Services::Request
Defined in:
lib/shamu/attributes/assignment.rb

Overview

Provide a means for defining writable attributes.

Class Method Summary collapse

Class Method Details

.attribute(name, *args, **options, &block)

This method returns an undefined value.

Define a new attribute for the class.

Examples:


class Params
  include Shamu::Attributes
  include Shamu::Attributes::Assignment

  attribute :created_at, coerce: :to_datetime
  attribute :count, coerce: :to_i
  attribute :label, coerce: ->(value){ value.upcase.to_sym }
  attribute :tags, coerce: :to_s, array: true
end

Parameters:

  • coerce (Symbol, #call)

    name of a method on the assigned value to call, or a custom method that can parse values when assigning the attribute.

  • array (Boolean)

    true if the expected value should be an array.



38
39
40
41
42
# File 'lib/shamu/attributes/assignment.rb', line 38

def attribute( name, *args, **options, &block )
  super
  define_attribute_assignment( name, **options )
  define_attribute_writer( name, **options )
end