Module: EntitySchema::Dsl

Includes:
SetupField
Defined in:
lib/entity_schema/dsl.rb

Overview

class-level methods for define entity_schema

Instance Method Summary collapse

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)
  options    = Transformers::BelongsTo.(name, to_s, type, opts)
  fk, object = Fields::Builders::BelongsTo.(options)
  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)
  options =   Transformers::Collection.(name, to_s, type, opts)
  setup_field Fields::Collection.new(options)
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)
  options =   Transformers::Object.(name, to_s, type, opts)
  setup_field Fields::Object.new(options)
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)
  options =   Transformers::Property.(name, to_s, nil, opts)
  setup_field Fields::Property.new(options)
end

#property?(name, **opts) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/entity_schema/dsl.rb', line 25

def property?(name, **opts)
  property(name, opts.merge!(predicate: true))
end