module EntitySchema::Dsl
class-level methods for define entity_schema
Public Instance Methods
belongs_to(name, type = nil, **opts)
click to toggle source
# 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)
click to toggle source
# 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
Also aliased as: has_many
object(name, type = nil, **opts)
click to toggle source
# 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
Also aliased as: has_one
property(name, **opts)
click to toggle source
# 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)
click to toggle source
# File lib/entity_schema/dsl.rb, line 25 def property?(name, **opts) property(name, opts.merge!(predicate: true)) end
Private Instance Methods
__merge(opts, other)
click to toggle source
# File lib/entity_schema/dsl.rb, line 61 def __merge(opts, other) opts.merge(other) { |_, old, new| new.nil? ? old : new } end