Module: Cequel::Model::Properties::ClassMethods
- Defined in:
- lib/cequel/model/properties.rb
Instance Method Summary collapse
- #column(name, type, options = {}) ⇒ Object
- #column_names ⇒ Object
- #columns ⇒ Object
- #key(key_alias, type) ⇒ Object
- #key_alias ⇒ Object
- #key_column ⇒ Object
- #type_column ⇒ Object
Instance Method Details
#column(name, type, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cequel/model/properties.rb', line 34 def column(name, type, = {}) name = name.to_sym @_cequel.add_column(name, type, .symbolize_keys) module_eval <<-RUBY, __FILE__, __LINE__+1 def #{name} read_attribute(#{name.inspect}) end def #{name}=(value) write_attribute(#{name.inspect}, value) end RUBY if type == :boolean module_eval <<-RUBY, __FILE__, __LINE__+1 if type == :boolean def #{name}? !!read_attribute(#{name.inspect}) end RUBY end end |
#column_names ⇒ Object
65 66 67 |
# File 'lib/cequel/model/properties.rb', line 65 def column_names [@_cequel.key.name, *@_cequel.columns.keys] end |
#columns ⇒ Object
69 70 71 |
# File 'lib/cequel/model/properties.rb', line 69 def columns [@_cequel.key, *@_cequel.columns.values] end |
#key(key_alias, type) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cequel/model/properties.rb', line 15 def key(key_alias, type) key_alias = key_alias.to_sym @_cequel.key = Column.new(key_alias, type) module_eval(<<-RUBY, __FILE__, __LINE__+1) def #{key_alias} @_cequel.key end def #{key_alias}=(key) @_cequel.key = key end def to_key [@_cequel.key] end RUBY end |
#key_alias ⇒ Object
57 58 59 |
# File 'lib/cequel/model/properties.rb', line 57 def key_alias key_column.name end |
#key_column ⇒ Object
61 62 63 |
# File 'lib/cequel/model/properties.rb', line 61 def key_column @_cequel.key end |
#type_column ⇒ Object
73 74 75 |
# File 'lib/cequel/model/properties.rb', line 73 def type_column @_cequel.type_column end |