module Quandl::Cassandra::Base::Attributes

Public Class Methods

new(*args) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 45
def initialize(*args)
  attrs = args.extract_options!
  @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

Public Instance Methods

assign_attributes(hash) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 63
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() click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 69
def attributes
  @attributes ||= self.class.attribute_names.inject({}){|m,k| m[k] ||= nil; m }
end
attributes=(value) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 73
def attributes=(value)
  @attributes = value.symbolize_keys! if value.is_a?(Hash)
end
inspect() click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 59
def inspect
  "#{self.class.name} " + attributes.inspect
end
reload() click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 77
def reload
  return false unless primary_key?
  clear_changes!
  reload_attributes
  true
end

Protected Instance Methods

attribute_changed?(attribute) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 95
def attribute_changed?(attribute)
  !changes[attribute.to_s].nil?
end
clear_changes!() click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 99
def clear_changes!
  @previously_changed = {}
  @changed_attributes.clear
end
cycle_changes!() click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 104
def cycle_changes!
  @previously_changed = changes
  @changed_attributes.clear
end
read_attribute(attribute) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 91
def read_attribute(attribute)
  @attributes[:"#{attribute}"]
end
write_attribute(attribute, value) click to toggle source
# File lib/quandl/cassandra/base/attributes.rb, line 86
def write_attribute(attribute, value)
  self.send(:"#{attribute}_will_change!") if self.attributes[:"#{attribute}"] != value
  @attributes[:"#{attribute}"] = value
end