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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rom/model_builder.rb', line 45 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.
18 19 20 |
# File 'lib/rom/model_builder.rb', line 18 def const_name @const_name end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
18 19 20 |
# File 'lib/rom/model_builder.rb', line 18 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/rom/model_builder.rb', line 16 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
18 19 20 |
# File 'lib/rom/model_builder.rb', line 18 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
27 28 29 30 31 32 33 |
# File 'lib/rom/model_builder.rb', line 27 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
40 41 42 |
# File 'lib/rom/model_builder.rb', line 40 def self.call(*args) new(*args).call end |
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
74 75 76 77 78 |
# File 'lib/rom/model_builder.rb', line 74 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
65 66 67 |
# File 'lib/rom/model_builder.rb', line 65 def define_const namespace.const_set(const_name, klass) end |