Class: ActiveRecordProperties::Property

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/active_record_properties/property.rb', line 6

def column
  @column
end

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/active_record_properties/property.rb', line 6

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/active_record_properties/property.rb', line 6

def name
  @name
end

#typeObject (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_valueObject



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