Module: Reaction::HasAttributes

Included in:
Action
Defined in:
lib/reaction/has_attributes.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/reaction/has_attributes.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attributesObject



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

def attributes
  ret = {}
  self.class.attributes.each do |name|
    ret[name] = send(name)
  end
  ret
end

#set_attributes(attributes = {}) ⇒ Object



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

def set_attributes(attributes = {})
  attributes.each do |key, value|
    if self.class.attributes.include?(key)
      send("#{key}=", value)
    end
  end
end

#validate_attributesObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/reaction/has_attributes.rb', line 54

def validate_attributes
  self.class.attributes.each do |attribute|
    unless send(attribute)
      # This is a server side error - we didn't set a valid attribute
      # for some reason, and attributes are things the server sets.
      failure(AttributeError.new(attribute))
      return false
    end
  end
end