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, **opts) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/entity_schema/dsl.rb', line 54

def belongs_to(name, **opts)
  Fields::Contracts::BelongsTo.(opts)
  specicifation = Fields::Specifications::BelongsTo.new(name, to_s, opts)
  fk, object = Fields::Builders::BelongsTo.(specicifation)
  setup_field(object, specicifation)
  setup_field(fk, specicifation)
end

#collection(name, **opts) ⇒ Object Also known as: has_many



45
46
47
48
49
50
# File 'lib/entity_schema/dsl.rb', line 45

def collection(name, **opts)
  Fields::Contracts::Collection.(opts)
  specicifation = Fields::Specifications::Collection.new(name, to_s, opts)
  field         = Fields::Collection.new(specicifation)
  setup_field(field, specicifation)
end

#object(name, **opts) ⇒ Object Also known as: has_one



36
37
38
39
40
41
# File 'lib/entity_schema/dsl.rb', line 36

def object(name, **opts)
  Fields::Contracts::Object.(opts)
  specicifation = Fields::Specifications::Object.new(name, to_s, opts)
  field         = Fields::Object.new(specicifation)
  setup_field(field, specicifation)
end

#property(name, **opts) ⇒ Object



29
30
31
32
33
34
# File 'lib/entity_schema/dsl.rb', line 29

def property(name, **opts)
  Fields::Contracts::Property.(opts)
  specicifation = Fields::Specifications::Property.new(name, to_s, opts)
  field         = Fields::Property.new(specicifation)
  setup_field(field, specicifation)
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