Module: CassandraObject::Attributes

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods
Included in:
Base
Defined in:
lib/cassandra_object/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/cassandra_object/attributes.rb', line 78

def method_missing(method_id, *args, &block)
  if !self.class.attribute_methods_generated?
    self.class.define_attribute_methods
    send(method_id, *args, &block)
  else
    super
  end
end

Instance Method Details

#attributes=(attributes) ⇒ Object



72
73
74
75
76
# File 'lib/cassandra_object/attributes.rb', line 72

def attributes=(attributes)
  attributes.each do |(name, value)|
    send("#{name}=", value)
  end
end

#read_attribute(name) ⇒ Object



68
69
70
# File 'lib/cassandra_object/attributes.rb', line 68

def read_attribute(name)
  @attributes[name.to_s]
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/cassandra_object/attributes.rb', line 87

def respond_to?(*args)
  self.class.define_attribute_methods unless self.class.attribute_methods_generated?
  super
end

#write_attribute(name, value) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/cassandra_object/attributes.rb', line 60

def write_attribute(name, value)
  if ma = self.class.model_attributes[name]
    @attributes[name.to_s] = ma.check_value!(value)
  else
    raise NoMethodError, "Unknown attribute #{name.inspect}"
  end
end