Module: HasAttributes

Defined in:
lib/has_attributes.rb,
lib/has_attributes/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/has_attributes.rb', line 5

def self.included(base)
  base.class.send(:attr_accessor, :model_attributes)
  base.extend(ClassMethods)
end

Instance Method Details

#attributesObject



46
47
48
49
50
51
52
53
# File 'lib/has_attributes.rb', line 46

def attributes
  (self.class.model_attributes || Set.new).reduce({}) do |memo, attr|
    unless (value = public_send(attr)).nil?
      memo[attr] = value
    end
    memo
  end
end

#attributes=(attrs) ⇒ Object



40
41
42
43
44
# File 'lib/has_attributes.rb', line 40

def attributes=(attrs)
  (self.class.model_attributes || Set.new).each do |attr|
    public_send((attr.to_s << "=").to_sym, attrs[attr])
  end
end