Class: Hemp::Orm::Property
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#primary_key ⇒ Object
readonly
Returns the value of attribute primary_key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, options = {}) ⇒ Property
constructor
A new instance of Property.
- #parse_options ⇒ Object
- #set_default_options ⇒ Object
- #supported_type?(arg) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Property
5 6 7 8 9 |
# File 'lib/hemp/orm/property.rb', line 5 def initialize(name, = {}) @name = name @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/hemp/orm/property.rb', line 4 def name @name end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
4 5 6 |
# File 'lib/hemp/orm/property.rb', line 4 def nullable @nullable end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/hemp/orm/property.rb', line 4 def @options end |
#primary_key ⇒ Object (readonly)
Returns the value of attribute primary_key.
4 5 6 |
# File 'lib/hemp/orm/property.rb', line 4 def primary_key @primary_key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/hemp/orm/property.rb', line 4 def type @type end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 |
# File 'lib/hemp/orm/property.rb', line 44 def ==(other) name == other.name end |
#parse_options ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hemp/orm/property.rb', line 11 def @options.each_pair do |key, value| case key when :type instance_variable_set("@type", value) if supported_type? value when :primary_key, :nullable instance_variable_set "@#{key}", value end end end |
#set_default_options ⇒ Object
23 24 25 26 27 |
# File 'lib/hemp/orm/property.rb', line 23 def @type = "text" @primary_key = false @nullable = true end |
#supported_type?(arg) ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/hemp/orm/property.rb', line 36 def supported_type?(arg) if %w(boolean integer text).include? arg.to_s true else raise DatabaseError.new "Type parameter passed in not supported." end end |
#to_s ⇒ Object
29 30 31 32 33 34 |
# File 'lib/hemp/orm/property.rb', line 29 def to_s "#{name} #{type}" << (nullable ? "" : " not null") << (primary_key ? " primary key" : "") << (primary_key && type == :integer ? " autoincrement" : "") end |