Module: Quandl::Cassandra::Base::Attributes::ClassMethods

Defined in:
lib/quandl/cassandra/base/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_namesObject



39
40
41
# File 'lib/quandl/cassandra/base/attributes.rb', line 39

def attribute_names
  @attribute_names ||= []
end

#define_attribute(name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/quandl/cassandra/base/attributes.rb', line 21

def define_attribute(name)
  name = name.to_sym
  self.class_eval do
    define_attribute_methods [name.to_sym]
  end
  define_method(name) do
    read_attribute(name)
  end
  define_method("#{name}=") do |value|
    write_attribute(name, value)
  end
  define_method("#{name}?") do
    read_attribute(name).present?
  end
  # store an array of defined attriubte names
  attribute_names << name unless attribute_names.include?(name)
end

#define_attributes(*names) ⇒ Object



16
17
18
19
# File 'lib/quandl/cassandra/base/attributes.rb', line 16

def define_attributes(*names)
  Array(names).each{|name| define_attribute(name) }
  Quandl::Logger.info("The attributes for #{self.to_s} are #{Array(names).join(', ')}")
end