Class: ROM::ModelBuilder
- Inherits:
-
Object
- Object
- ROM::ModelBuilder
- Defined in:
- lib/rom/model_builder.rb
Overview
Model builders can be used to build model classes for mappers
This is used when you define a mapper and setup a model using :name option.
Direct Known Subclasses
Defined Under Namespace
Classes: PORO
Instance Attribute Summary collapse
-
#const_name ⇒ Object
readonly
Returns the value of attribute const_name.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Class Method Summary collapse
-
.[](type) ⇒ Class
private
Return model builder subclass based on type.
-
.call(*args) ⇒ Class
private
Build a model class.
Instance Method Summary collapse
-
#call(attrs) ⇒ Class
private
Build a model class supporting specific attributes.
-
#define_const ⇒ Object
private
Define a model class constant.
-
#initialize(options = {}) ⇒ ModelBuilder
constructor
private
A new instance of ModelBuilder.
Constructor Details
#initialize(options = {}) ⇒ ModelBuilder
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 a new instance of ModelBuilder.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rom/model_builder.rb', line 51 def initialize( = {}) @name = [:name] if name parts = name.split('::') @const_name = parts.pop @namespace = if parts.any? Inflector.constantize(parts.join('::')) else Object end end end |
Instance Attribute Details
#const_name ⇒ Object (readonly)
Returns the value of attribute const_name.
22 23 24 |
# File 'lib/rom/model_builder.rb', line 22 def const_name @const_name end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
26 27 28 |
# File 'lib/rom/model_builder.rb', line 26 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/rom/model_builder.rb', line 20 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
24 25 26 |
# File 'lib/rom/model_builder.rb', line 24 def namespace @namespace end |
Class Method Details
.[](type) ⇒ Class
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.
Return model builder subclass based on type
35 36 37 38 39 40 41 |
# File 'lib/rom/model_builder.rb', line 35 def self.[](type) case type when :poro then PORO else raise ::ArgumentError, "#{type.inspect} is not a supported model type" end end |
.call(*args) ⇒ Class
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.
Build a model class
48 |
# File 'lib/rom/model_builder.rb', line 48 def self.call(*args) = new(*args).call |
Instance Method Details
#call(attrs) ⇒ Class
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.
Build a model class supporting specific attributes
78 79 80 81 82 |
# File 'lib/rom/model_builder.rb', line 78 def call(attrs) define_class(attrs) define_const if const_name @klass end |
#define_const ⇒ 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.
Define a model class constant
71 |
# File 'lib/rom/model_builder.rb', line 71 def define_const = namespace.const_set(const_name, klass) |