Class: ROM::Schema::DSL
- Inherits:
- BasicObject
- Defined in:
- core/lib/rom/schema/dsl.rb
Overview
Schema DSL exposed as schema { .. }
in relation classes
Constant Summary collapse
- KERNEL_METHODS =
%i[extend method].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Symbol
readonly
The adapter identifier used in gateways.
- #associations_dsl ⇒ Object readonly
-
#attr_class ⇒ Class
readonly
Attribute class that should be used.
- #attributes ⇒ Object readonly
- #definition ⇒ Object readonly
-
#inferrer ⇒ Inferrer
readonly
Optional attribute inferrer.
- #plugins ⇒ Object readonly
-
#relation ⇒ Relation::Name
readonly
The name of the schema's relation.
-
#schema_class ⇒ Class
readonly
Schema class that should be instantiated.
Instance Method Summary collapse
-
#associations(&block) ⇒ AssociationDSL
Define associations for a relation.
-
#attribute(name, type_or_options, options = EMPTY_HASH) ⇒ Object
Defines a relation attribute with its type and options.
-
#primary_key(*names) ⇒ Object
Specify which key(s) should be the primary key.
-
#use(plugin_name, options = ::ROM::EMPTY_HASH) ⇒ Object
Enables for the schema.
Instance Attribute Details
#adapter ⇒ Symbol (readonly)
Returns The adapter identifier used in gateways.
38 |
# File 'core/lib/rom/schema/dsl.rb', line 38 option :adapter, default: -> { :default } |
#associations_dsl ⇒ Object (readonly)
57 58 59 |
# File 'core/lib/rom/schema/dsl.rb', line 57 def associations_dsl @associations_dsl end |
#attr_class ⇒ Class (readonly)
Returns Attribute class that should be used.
34 |
# File 'core/lib/rom/schema/dsl.rb', line 34 option :attr_class, default: -> { Attribute } |
#attributes ⇒ Object (readonly)
45 46 47 |
# File 'core/lib/rom/schema/dsl.rb', line 45 def attributes @attributes end |
#definition ⇒ Object (readonly)
53 54 55 |
# File 'core/lib/rom/schema/dsl.rb', line 53 def definition @definition end |
#inferrer ⇒ Inferrer (readonly)
Returns Optional attribute inferrer.
26 |
# File 'core/lib/rom/schema/dsl.rb', line 26 option :inferrer, default: -> { DEFAULT_INFERRER } |
#plugins ⇒ Object (readonly)
49 50 51 |
# File 'core/lib/rom/schema/dsl.rb', line 49 def plugins @plugins end |
#relation ⇒ Relation::Name (readonly)
Returns The name of the schema's relation.
22 |
# File 'core/lib/rom/schema/dsl.rb', line 22 param :relation |
#schema_class ⇒ Class (readonly)
Returns Schema class that should be instantiated.
30 |
# File 'core/lib/rom/schema/dsl.rb', line 30 option :schema_class, default: -> { Schema } |
Instance Method Details
#associations(&block) ⇒ AssociationDSL
Define associations for a relation
117 118 119 |
# File 'core/lib/rom/schema/dsl.rb', line 117 def associations(&block) @associations_dsl = AssociationsDSL.new(relation, &block) end |
#attribute(name, type_or_options, options = EMPTY_HASH) ⇒ Object
Defines a relation attribute with its type and options.
When only options are given, type is left as nil. It makes sense when it is used alongside an schema inferrer, which will populate the type.
79 80 81 82 83 84 85 86 |
# File 'core/lib/rom/schema/dsl.rb', line 79 def attribute(name, , = EMPTY_HASH) if attributes.key?(name) ::Kernel.raise ::ROM::AttributeAlreadyDefinedError, "Attribute #{name.inspect} already defined" end attributes[name] = build_attribute_info(name, , ) end |
#primary_key(*names) ⇒ Object
Specify which key(s) should be the primary key
158 159 160 161 162 163 164 |
# File 'core/lib/rom/schema/dsl.rb', line 158 def primary_key(*names) names.each do |name| attributes[name][:type] = attributes[name][:type].(primary_key: true) end self end |