module ROM::Mapper::ModelDSL
Model DSL
allows setting a model class
@private
Constants
- DEFAULT_TYPE
Attributes
attributes[R]
builder[R]
klass[R]
Public Instance Methods
model(options = nil)
click to toggle source
Set or generate a model
@example
class MyDefinition include ROM::Mapper::ModelDSL def initialize @attributes = [[:name], [:title]] end end definition = MyDefinition.new # just set a model constant definition.model(User) # generate model class for the attributes definition.model(name: 'User')
@api public
# File lib/rom/mapper/model_dsl.rb, line 33 def model(options = nil) if options.is_a?(Class) @klass = options elsif options type = options.fetch(:type) { DEFAULT_TYPE } @builder = ModelBuilder[type].new(options) end build_class unless options end
Private Instance Methods
build_class()
click to toggle source
Build a model class using a specialized builder
@api private
# File lib/rom/mapper/model_dsl.rb, line 49 def build_class return klass if klass included_attrs = attributes.reject do |_name, opts| opts && opts[:exclude] end builder.call(included_attrs.map(&:first)) if builder end