Class: ViewModel::TestHelpers::ARVMBuilder::Spec
- Inherits:
-
Struct
- Object
- Struct
- ViewModel::TestHelpers::ARVMBuilder::Spec
- Defined in:
- lib/view_model/test_helpers/arvm_builder.rb,
lib/view_model/test_helpers/arvm_builder.rb
Overview
Building an ARVM requires three blocks, to define schema, model and viewmodel. Support providing these either in an spec argument or as a dsl-style builder.
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#viewmodel ⇒ Object
Returns the value of attribute viewmodel.
Instance Method Summary collapse
-
#initialize(schema:, model:, viewmodel:) ⇒ Spec
constructor
A new instance of Spec.
- #merge(schema: nil, model: nil, viewmodel: nil) ⇒ Object
Constructor Details
#initialize(schema:, model:, viewmodel:) ⇒ Spec
Returns a new instance of Spec.
11 12 13 |
# File 'lib/view_model/test_helpers/arvm_builder.rb', line 11 def initialize(schema:, model:, viewmodel:) super(schema, model, viewmodel) end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model
9 10 11 |
# File 'lib/view_model/test_helpers/arvm_builder.rb', line 9 def model @model end |
#schema ⇒ Object
Returns the value of attribute schema
9 10 11 |
# File 'lib/view_model/test_helpers/arvm_builder.rb', line 9 def schema @schema end |
#viewmodel ⇒ Object
Returns the value of attribute viewmodel
9 10 11 |
# File 'lib/view_model/test_helpers/arvm_builder.rb', line 9 def viewmodel @viewmodel end |
Instance Method Details
#merge(schema: nil, model: nil, viewmodel: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/view_model/test_helpers/arvm_builder.rb', line 15 def merge(schema: nil, model: nil, viewmodel: nil) this_schema = self.schema this_model = self.model this_viewmodel = self.viewmodel Spec.new( schema: ->(t) do this_schema.(t) schema&.(t) end, model: ->(m) do m.class_eval(&this_model) model.try { |b| m.class_eval(&b) } end, viewmodel: ->(v) do v.class_eval(&this_viewmodel) viewmodel.try { |b| v.class_eval(&b) } end) end |