class Bright::Model
Public Class Methods
attribute_names()
click to toggle source
# File lib/bright/model.rb, line 21 def self.attribute_names @attribute_names end
new(attributes={})
click to toggle source
Calls superclass method
# File lib/bright/model.rb, line 5 def initialize(attributes={}) assign_attributes(attributes) if attributes super() end
Public Instance Methods
assign_attributes(new_attributes)
click to toggle source
# File lib/bright/model.rb, line 11 def assign_attributes(new_attributes) if !new_attributes.is_a?(Hash) raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." end return if new_attributes.empty? attributes = Hash[new_attributes.collect{|k,v| [k.to_sym, v]}] _assign_attributes(attributes) end
to_json()
click to toggle source
# File lib/bright/model.rb, line 25 def to_json Hash[self.class.attribute_names.collect do |n| [n, self.send(n)] end].to_json end
Private Instance Methods
_assign_attribute(k, v)
click to toggle source
# File lib/bright/model.rb, line 39 def _assign_attribute(k, v) if respond_to?("#{k}=") public_send("#{k}=", v) else raise UnknownAttributeError.new(self, k) end end
_assign_attributes(attributes)
click to toggle source
# File lib/bright/model.rb, line 33 def _assign_attributes(attributes) attributes.each do |k, v| _assign_attribute(k, v) end end