Class: ActiveRecordProperties::Property
- Inherits:
-
Object
- Object
- ActiveRecordProperties::Property
- Defined in:
- lib/active_record_properties/property.rb
Overview
Represents a single property definition
Constant Summary collapse
- SUPPORTED_TYPES =
%i[string integer float boolean hash array].freeze
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #default_value ⇒ Object
-
#initialize(name, type: :string, default: nil, column: :properties) ⇒ Property
constructor
A new instance of Property.
Constructor Details
#initialize(name, type: :string, default: nil, column: :properties) ⇒ Property
Returns a new instance of Property.
10 11 12 13 14 15 16 17 |
# File 'lib/active_record_properties/property.rb', line 10 def initialize(name, type: :string, default: nil, column: :properties) @name = name.to_sym @type = type.to_sym @default = default @column = column.to_sym validate_type! end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
6 7 8 |
# File 'lib/active_record_properties/property.rb', line 6 def column @column end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/active_record_properties/property.rb', line 6 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_record_properties/property.rb', line 6 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/active_record_properties/property.rb', line 6 def type @type end |
Instance Method Details
#default_value ⇒ Object
19 20 21 22 |
# File 'lib/active_record_properties/property.rb', line 19 def default_value return default.call if default.respond_to?(:call) default end |