Class: HoboFields::FieldDeclarationDsl

Inherits:
BlankSlate
  • Object
show all
Defined in:
lib/hobo_fields/field_declaration_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ FieldDeclarationDsl

Returns a new instance of FieldDeclarationDsl.



5
6
7
# File 'lib/hobo_fields/field_declaration_dsl.rb', line 5

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



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

def method_missing(name, *args)
  field(name, *args)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

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



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

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

#timestampsObject



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

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