Class: LcpRuby::ModelFactory::ApiBuilder
- Inherits:
-
Object
- Object
- LcpRuby::ModelFactory::ApiBuilder
- Defined in:
- lib/lcp_ruby/model_factory/api_builder.rb
Overview
Builds API-backed model classes using ActiveModel instead of ActiveRecord. Only applies compatible steps from the standard Builder.
Constant Summary collapse
- TYPE_MAP =
Mapping from YAML field types to ActiveModel attribute types
{ "string" => :string, "text" => :string, "integer" => :integer, "float" => :float, "decimal" => :decimal, "boolean" => :boolean, "date" => :date, "datetime" => :datetime, "enum" => :string, "uuid" => :string, "email" => :string, "phone" => :string, "url" => :string, "color" => :string, "json" => :string, "array" => :string }.freeze
Instance Attribute Summary collapse
-
#model_definition ⇒ Object
readonly
Returns the value of attribute model_definition.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(model_definition) ⇒ ApiBuilder
constructor
A new instance of ApiBuilder.
Constructor Details
#initialize(model_definition) ⇒ ApiBuilder
Returns a new instance of ApiBuilder.
28 29 30 |
# File 'lib/lcp_ruby/model_factory/api_builder.rb', line 28 def initialize(model_definition) @model_definition = model_definition end |
Instance Attribute Details
#model_definition ⇒ Object (readonly)
Returns the value of attribute model_definition.
26 27 28 |
# File 'lib/lcp_ruby/model_factory/api_builder.rb', line 26 def model_definition @model_definition end |
Instance Method Details
#build ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lcp_ruby/model_factory/api_builder.rb', line 32 def build model_class = create_model_class apply_attributes(model_class) apply_enums(model_class) apply_label_method(model_class) apply_model_extensions(model_class) model_class.lcp_model_definition = model_definition model_class rescue => e raise LcpRuby::MetadataError, "Failed to build API model '#{model_definition.name}': #{e.}" end |