Module: CleanModel::Base::InstanceMethods

Defined in:
lib/clean_model/base.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attributes) ⇒ Object



49
50
51
52
53
54
# File 'lib/clean_model/base.rb', line 49

def assign_attributes(attributes)
  return nil unless attributes
  attributes.each do |name, value|
    send("#{name}=", value) if respond_to?("#{name}=")
  end
end

#attributesObject



56
57
58
# File 'lib/clean_model/base.rb', line 56

def attributes
  Hash[self.class.attribute_names.map { |a| [a, send(a)] }]
end

#initialize(attributes = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/clean_model/base.rb', line 40

def initialize(attributes={})
  self.class.attributes.each { |a| a.assign_default(self) }
  if block_given?
    yield(self)
  else
    assign_attributes attributes
  end
end