Class: DeclareSchema::FieldDeclarationDsl
- Inherits:
- BasicObject
- Includes:
- Kernel
- Defined in:
- lib/declare_schema/field_declaration_dsl.rb
Overview
avoid Object because that gets extended by lots of gems
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #field(name, type, *args, **options) ⇒ Object
-
#initialize(model, **options) ⇒ FieldDeclarationDsl
constructor
A new instance of FieldDeclarationDsl.
- #method_missing(name, *args, **options) ⇒ Object
- #optimistic_lock ⇒ Object
- #timestamps ⇒ Object
Constructor Details
#initialize(model, **options) ⇒ FieldDeclarationDsl
Returns a new instance of FieldDeclarationDsl.
15 16 17 18 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 15 def initialize(model, **) @model = model @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **options) ⇒ Object
35 36 37 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 35 def method_missing(name, *args, **) field(name, *args, **) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
20 21 22 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 20 def model @model end |
Instance Method Details
#field(name, type, *args, **options) ⇒ Object
31 32 33 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 31 def field(name, type, *args, **) @model.declare_field(name, type, *args, **@options.merge()) end |
#optimistic_lock ⇒ Object
27 28 29 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 27 def optimistic_lock field(:lock_version, :integer, default: 1, null: false) end |
#timestamps ⇒ Object
22 23 24 25 |
# File 'lib/declare_schema/field_declaration_dsl.rb', line 22 def field(:created_at, :datetime, null: true) field(:updated_at, :datetime, null: true) end |