Module: Commutator::Model::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Commutator::Model
Defined in:
lib/commutator/model/attributes.rb

Overview

This module provides methods related to registering attributes and generating attr_accessors, ultimately for the purpose of enabling Commutator::Model to know which attributes to send to the db.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attrs = {}) ⇒ Object



9
10
11
12
13
# File 'lib/commutator/model/attributes.rb', line 9

def assign_attributes(attrs = {})
  attrs.slice(*attribute_names).each do |attr_name, value|
    send("#{attr_name}=", value)
  end
end

#attribute_namesObject



21
22
23
# File 'lib/commutator/model/attributes.rb', line 21

def attribute_names
  self.class.attribute_names
end

#attributesObject



15
16
17
18
19
# File 'lib/commutator/model/attributes.rb', line 15

def attributes
  attribute_names.each_with_object({}) do |attr_name, hash|
    hash[attr_name] = send(attr_name)
  end
end