Module: Quandl::Cassandra::Base::Attributes
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/quandl/cassandra/base/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #assign_attributes(hash) ⇒ Object
- #attributes ⇒ Object
- #attributes=(value) ⇒ Object
- #initialize(*args) ⇒ Object
- #inspect ⇒ Object
- #reload ⇒ Object
Instance Method Details
#assign_attributes(hash) ⇒ Object
62 63 64 65 66 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 62 def assign_attributes(hash) hash.each do |k,v| send("#{k}=", v) if self.class.attribute_names.include?(k) && respond_to?("#{k}=") end end |
#attributes ⇒ Object
68 69 70 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 68 def attributes @attributes ||= self.class.attribute_names.inject({}){|m,k| m[k] ||= nil; m } end |
#attributes=(value) ⇒ Object
72 73 74 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 72 def attributes=(value) @attributes = value.symbolize_keys! if value.is_a?(Hash) end |
#initialize(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 44 def initialize(*args) attrs = args. @attributes = {} # result set attributes? result_set = attrs.delete(:_result_set) if attrs.has_key?(:_result_set) # assign if result_set.present? && result_set.is_a?(Hash) @attributes = result_set.symbolize_keys! self.new_record = false end # assign attributes self.assign_attributes(attrs) end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 58 def inspect "#{self.class.name} " + attributes.inspect end |
#reload ⇒ Object
76 77 78 79 80 81 |
# File 'lib/quandl/cassandra/base/attributes.rb', line 76 def reload return false unless primary_key? clear_changes! reload_attributes true end |