module DatastaxRails::AttributeMethods
Module
to hold attribute method related functionality
Methods for defining attributes on a model
Public Instance Methods
attribute_exists?(name)
click to toggle source
# File lib/datastax_rails/attribute_methods.rb, line 124 def attribute_exists?(name) @attributes.key?(name.to_s) end
attribute_for_inspect(attr_name)
click to toggle source
Returns an #inspect
-like string for the value of the attribute attr_name
. String attributes are truncated upto 50 characters, and Date and Time attributes are returned in the :db
format. Other attributes return the value of #inspect
without modification.
person = Person.create!(name: 'David Heinemeier Hansson ' * 3) person.attribute_for_inspect(:name) # => "\"David Heinemeier Hansson David Heinemeier Hansson D...\"" person.attribute_for_inspect(:created_at) # => "\"2012-10-22 00:15:07\""
# File lib/datastax_rails/attribute_methods.rb, line 159 def attribute_for_inspect(attr_name) value = read_attribute(attr_name) if value.is_a?(String) && value.length > 50 "#{value[0..50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") else value.inspect end end
column_for_attribute(name)
click to toggle source
# File lib/datastax_rails/attribute_methods.rb, line 142 def column_for_attribute(name) self.class.column_for_attribute(name) end
method_missing(method_id, *args, &block)
click to toggle source
Calls superclass method
# File lib/datastax_rails/attribute_methods.rb, line 128 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
respond_to?(*args)
click to toggle source
Calls superclass method
# File lib/datastax_rails/attribute_methods.rb, line 137 def respond_to?(*args) self.class.define_attribute_methods unless self.class.attribute_methods_generated? super end
Protected Instance Methods
attribute_method?(name)
click to toggle source
# File lib/datastax_rails/attribute_methods.rb, line 173 def attribute_method?(name) attribute_definitions.key?(name.to_sym) end
Private Instance Methods
attribute(name)
click to toggle source
# File lib/datastax_rails/attribute_methods.rb, line 193 def attribute(name) read_attribute(name) end
attribute=(name, value)
click to toggle source
# File lib/datastax_rails/attribute_methods.rb, line 197 def attribute=(name, value) write_attribute(name, value) end