Module: EntitySchema::Dsl
- Includes:
- SetupField
- Defined in:
- lib/entity_schema/dsl.rb
Overview
class-level methods for define entity_schema
Instance Method Summary collapse
- #belongs_to(name, type = nil, **opts) ⇒ Object
- #collection(name, type = nil, **opts) ⇒ Object (also: #has_many)
- #object(name, type = nil, **opts) ⇒ Object (also: #has_one)
- #property(name, **opts) ⇒ Object
- #property?(name, **opts) ⇒ Boolean
Methods included from SetupField
#setup_field, #setup_getter, #setup_predicate, #setup_setter
Instance Method Details
#belongs_to(name, type = nil, **opts) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/entity_schema/dsl.rb', line 51 def belongs_to(name, type = nil, **opts) Contracts::BelongsTo.(name, type, **opts) = Transformers::BelongsTo.(name, to_s, type, opts) fk, object = Fields::Builders::BelongsTo.() setup_field(object) setup_field(fk) end |
#collection(name, type = nil, **opts) ⇒ Object Also known as: has_many
43 44 45 46 47 |
# File 'lib/entity_schema/dsl.rb', line 43 def collection(name, type = nil, **opts) Contracts::Collection.(name, type, **opts) = Transformers::Collection.(name, to_s, type, opts) setup_field Fields::Collection.new() end |
#object(name, type = nil, **opts) ⇒ Object Also known as: has_one
35 36 37 38 39 |
# File 'lib/entity_schema/dsl.rb', line 35 def object(name, type = nil, **opts) Contracts::Object.(name, type, **opts) = Transformers::Object.(name, to_s, type, opts) setup_field Fields::Object.new() end |
#property(name, **opts) ⇒ Object
29 30 31 32 33 |
# File 'lib/entity_schema/dsl.rb', line 29 def property(name, **opts) Contracts::Property.(name, **opts) = Transformers::Property.(name, to_s, nil, opts) setup_field Fields::Property.new() end |
#property?(name, **opts) ⇒ Boolean
25 26 27 |
# File 'lib/entity_schema/dsl.rb', line 25 def property?(name, **opts) property(name, opts.merge!(predicate: true)) end |