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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rom/model_builder.rb', line 49 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.
22 23 24 |
# File 'lib/rom/model_builder.rb', line 22 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.
22 23 24 |
# File 'lib/rom/model_builder.rb', line 22 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
31 32 33 34 35 36 37 |
# File 'lib/rom/model_builder.rb', line 31 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
44 45 46 |
# File 'lib/rom/model_builder.rb', line 44 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
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
69 70 71 |
# File 'lib/rom/model_builder.rb', line 69 def define_const namespace.const_set(const_name, klass) end |