Class: ActiveRecordProperties::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_properties/dsl.rb

Overview

DSL for defining properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column) ⇒ DSL

Returns a new instance of DSL.



8
9
10
11
# File 'lib/active_record_properties/dsl.rb', line 8

def initialize(column)
  @column = column
  @properties = []
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

#property(name, type: :string, default: nil) ⇒ Object

Define a property

Examples:

property :income_tax_rate, type: :float, default: 13.0
property :settings, type: :hash, default: -> { {} }

Parameters:

  • name (Symbol, String)

    Property name

  • type (Symbol) (defaults to: :string)

    Property type (:string, :integer, :float, :boolean, :hash, :array)

  • default (Object, Proc) (defaults to: nil)

    Default value or proc



22
23
24
25
# File 'lib/active_record_properties/dsl.rb', line 22

def property(name, type: :string, default: nil)
  prop = Property.new(name, type: type, default: default, column: column)
  @properties << prop
end