Class: ROM::Schema::DSL Deprecated
- Inherits:
-
Object
- Object
- ROM::Schema::DSL
- Extended by:
- Initializer
- Defined in:
- lib/rom/compat/schema/dsl.rb
Overview
Schema DSL exposed as schema { .. }
in relation classes
Instance Attribute Summary collapse
-
#adapter ⇒ Symbol
readonly
The adapter identifier used in gateways.
-
#attr_class ⇒ Class
readonly
Attribute class that should be used.
-
#attributes ⇒ Hash<Symbol, Hash>
readonly
keys and attribute representations as values.
-
#definition ⇒ Class
readonly
An optional block that will be evaluated as part of this DSL.
-
#inflector ⇒ Dry::Inflector
readonly
private
String inflector.
- #plugins ⇒ Array<Plugin> readonly
-
#relation ⇒ Relation::Name
readonly
The name of the schema's relation.
Class Method Summary collapse
- .new(**options, &block) ⇒ Object private
Instance Method Summary collapse
- #__assoc_dsl__ ⇒ Object private
-
#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.
- #call ⇒ Object private
- #config ⇒ Object private
- #inspect ⇒ Object
- #plugin(name, **options) ⇒ Object
-
#primary_key(*names) ⇒ Object
Specify which key(s) should be the primary key.
-
#use(name, **options) ⇒ Object
Enable a plugin in the schema DSL.
Instance Attribute Details
#adapter ⇒ Symbol (readonly)
Returns The adapter identifier used in gateways.
28 |
# File 'lib/rom/compat/schema/dsl.rb', line 28 option :adapter |
#attr_class ⇒ Class (readonly)
Returns Attribute class that should be used.
42 |
# File 'lib/rom/compat/schema/dsl.rb', line 42 option :attr_class, default: -> { Attribute } |
#attributes ⇒ Hash<Symbol, Hash> (readonly)
keys and attribute representations as values.
49 |
# File 'lib/rom/compat/schema/dsl.rb', line 49 option :attributes, default: -> { EMPTY_HASH.dup } |
#definition ⇒ Class (readonly)
Returns An optional block that will be evaluated as part of this DSL.
53 |
# File 'lib/rom/compat/schema/dsl.rb', line 53 option :definition, type: Types.Instance(Proc), default: -> { proc {} } |
#inflector ⇒ Dry::Inflector (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns String inflector.
33 |
# File 'lib/rom/compat/schema/dsl.rb', line 33 option :inflector, default: -> { Inflector } |
#plugins ⇒ Array<Plugin> (readonly)
57 |
# File 'lib/rom/compat/schema/dsl.rb', line 57 option :plugins, default: -> { EMPTY_ARRAY } |
#relation ⇒ Relation::Name (readonly)
Returns The name of the schema's relation.
24 |
# File 'lib/rom/compat/schema/dsl.rb', line 24 option :relation |
Class Method Details
.new(**options, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 |
# File 'lib/rom/compat/schema/dsl.rb', line 60 def self.new(**, &block) if block super(definition: block, **) else super end end |
Instance Method Details
#__assoc_dsl__ ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 |
# File 'lib/rom/compat/schema/dsl.rb', line 138 def __assoc_dsl__ @__assoc_dsl__ ||= AssociationsDSL.new(relation, inflector) end |
#associations(&block) ⇒ AssociationDSL
Define associations for a relation
129 130 131 132 133 134 135 |
# File 'lib/rom/compat/schema/dsl.rb', line 129 def associations(&block) if block __assoc_dsl__.instance_eval(&block) else __assoc_dsl__.registry.values end 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 a schema inferrer, which will populate the type.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rom/compat/schema/dsl.rb', line 77 def attribute(name, , = EMPTY_HASH) if attributes.include?(name) raise( ::ROM::AttributeAlreadyDefinedError, "Attribute #{name.inspect} already defined" ) end build_attribute_info(name, , ).tap do |attr_info| attributes[name] = attr_info end end |
#call ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
164 165 166 |
# File 'lib/rom/compat/schema/dsl.rb', line 164 def call schema_class.define(relation, **config) end |
#config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rom/compat/schema/dsl.rb', line 169 def config @config ||= begin # Enable available plugin's plugins.each do |plugin| next unless plugin.type == :schema plugin.enable(self) unless plugin.enabled? end # Apply custom definition block if it exists instance_eval(&definition) if definition # Apply plugin defaults plugins.each do |plugin| next unless plugin.type == :schema plugin.__send__(:apply_to, self) end attributes.freeze associations.freeze opts.freeze end end |
#inspect ⇒ Object
195 196 197 |
# File 'lib/rom/compat/schema/dsl.rb', line 195 def inspect %(<##{self.class} relation=#{relation} attributes=#{attributes} plugins=#{plugins}>) end |
#plugin(name, **options) ⇒ Object
157 158 159 160 161 |
# File 'lib/rom/compat/schema/dsl.rb', line 157 def plugin(name, **) plugin = plugins.detect { |pl| pl.name == name } plugin.config.update() unless .empty? plugin end |
#primary_key(*names) ⇒ Object
Specify which key(s) should be the primary key
93 94 95 96 97 98 |
# File 'lib/rom/compat/schema/dsl.rb', line 93 def primary_key(*names) names.each do |name| attributes[name][:type] = attributes[name][:type].(primary_key: true) end self end |