Class: Mongoose::BaseColumn
- Extended by:
- Forwardable
- Defined in:
- lib/mongoose/column.rb
Overview
BaseColumn class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
writeonly
Sets the attribute required.
-
#tbl_class ⇒ Object
readonly
Returns the value of attribute tbl_class.
Class Method Summary collapse
-
.create(tbl_class, name, col_def) ⇒ Object
———————————————————————– BaseColumn.create_table ———————————————————————–.
-
.valid_data_type?(data_type) ⇒ Boolean
———————————————————————– BaseColumn.valid_data_type? ———————————————————————–.
Instance Method Summary collapse
-
#close ⇒ Object
———————————————————————– close ———————————————————————–.
-
#convert_to_native(value) ⇒ Object
———————————————————————– convert_to_native ———————————————————————–.
-
#indexed? ⇒ Boolean
———————————————————————– indexed? ———————————————————————–.
-
#initialize(tbl_class, name, col_def) ⇒ BaseColumn
constructor
———————————————————————– initialize ———————————————————————–.
-
#required? ⇒ Boolean
———————————————————————– required? ———————————————————————–.
Constructor Details
#initialize(tbl_class, name, col_def) ⇒ BaseColumn
initialize
38 39 40 41 42 43 44 |
# File 'lib/mongoose/column.rb', line 38 def initialize(tbl_class, name, col_def) @tbl_class = tbl_class @name = name @data_type = col_def @indexed = false @required = false end |
Instance Attribute Details
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
7 8 9 |
# File 'lib/mongoose/column.rb', line 7 def data_type @data_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/mongoose/column.rb', line 7 def name @name end |
#required=(value) ⇒ Object (writeonly)
Sets the attribute required
8 9 10 |
# File 'lib/mongoose/column.rb', line 8 def required=(value) @required = value end |
#tbl_class ⇒ Object (readonly)
Returns the value of attribute tbl_class.
7 8 9 |
# File 'lib/mongoose/column.rb', line 7 def tbl_class @tbl_class end |
Class Method Details
.create(tbl_class, name, col_def) ⇒ Object
BaseColumn.create_table
31 32 33 |
# File 'lib/mongoose/column.rb', line 31 def self.create(tbl_class, name, col_def) return new(tbl_class, name, col_def) end |
.valid_data_type?(data_type) ⇒ Boolean
BaseColumn.valid_data_type?
24 25 26 |
# File 'lib/mongoose/column.rb', line 24 def self.valid_data_type?(data_type) DATA_TYPES.include?(data_type) end |
Instance Method Details
#convert_to_native(value) ⇒ Object
convert_to_native
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mongoose/column.rb', line 69 def convert_to_native(value) case @data_type when :string value.to_s when :integer value.to_i when :float value.to_f when :time Time.parse(value) when :date Date.parse(value) when :datetime DateTime.parse(value) when :boolean true if [true, 'true', 1].include?(value) end end |
#indexed? ⇒ Boolean
indexed?
49 50 51 |
# File 'lib/mongoose/column.rb', line 49 def indexed? @indexed end |
#required? ⇒ Boolean
required?
56 57 58 |
# File 'lib/mongoose/column.rb', line 56 def required? @required end |