Class: HoboFields::FieldDeclarationDsl

Inherits:
BlankSlate
  • Object
show all
Includes:
Types::EnumString::DeclarationHelper
Defined in:
lib/hobo_fields/field_declaration_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Types::EnumString::DeclarationHelper

#enum_string

Constructor Details

#initialize(model) ⇒ FieldDeclarationDsl

Returns a new instance of FieldDeclarationDsl.



9
10
11
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 9

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



27
28
29
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 27

def method_missing(name, *args)
  field(name, args.first, *args.rest)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 13

def model
  @model
end

Instance Method Details

#field(name, type, *args) ⇒ Object



22
23
24
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 22

def field(name, type, *args)
  @model.declare_field(name, type, *args)
end

#timestampsObject



16
17
18
19
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 16

def timestamps
  field(:created_at, :datetime)
  field(:updated_at, :datetime)
end