Sha256: 0b036734110e24741a54fd8fc019a8b9180a5b7b56de2565b5a0a1c3a92db9ab
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module Spread2RDF module Attributes extend ActiveSupport::Concern module ClassMethods def attributes if superclass.respond_to?(:attributes) and (super_attributes = superclass.attributes).is_a? Hash @attributes.reverse_merge(super_attributes) else @attributes end end def attributes=(defaults) defaults.each { |attribute, default_value| attr_accessor attribute } @attributes = @attributes.try(:merge, defaults) || defaults end end def init_attributes(initial_values) self.class.attributes.each do |attribute, default_value| instance_variable_set("@#{attribute}".to_sym, initial_values.delete(attribute) || default_value) end initial_values end def update_attributes(update_values) update_values.each do |attribute, value| next unless self.class.attributes.include? attribute instance_variable_set("@#{attribute}".to_sym, value) end update_values end def inspect "#{self}: " + self.class.attributes.map do |attribute, default_value| "#{attribute}=#{self.send(attribute)}" end.join(', ') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spread2rdf-0.0.1pre.1 | lib/spread2rdf/attributes.rb |