Class: ActionBlocks::MatchConditionBuilder

Inherits:
BaseBuilder
  • Object
show all
Defined in:
lib/action_blocks/builders/model_builder.rb

Overview

Base - Refers to the selecting model and fields on selecting model Related - Refers to the selected model and fields on selected model e.g. When a Work Order selects Items

Item is Related Model
WorkOrder is Base Model

When building a match condition, its defined in the Base Models builder. e.g. When a Work Order selects Items

This selection is declared in the Work Order Model

When using a selection to select related items, such as a table the Base Model (Work Order) feels a bit misnamed from this context as Items are being selected and form the foundation of the query.

Instance Attribute Summary collapse

Attributes inherited from BaseBuilder

#dsl_delegate, #id

Instance Method Summary collapse

Methods inherited from BaseBuilder

#after_build, #after_load, array_fields, block_type, builds, builds_many, delegate_class, #evaluate, #freeze, includes_scheme_helpers, #initialize, #is_block?, #key, references, sets, sets_many, #ui_reference, #valid?

Constructor Details

This class inherits a constructor from ActionBlocks::BaseBuilder

Instance Attribute Details

#base_field_idObject

Returns the value of attribute base_field_id.



176
177
178
# File 'lib/action_blocks/builders/model_builder.rb', line 176

def base_field_id
  @base_field_id
end

#parent_modelObject

Returns the value of attribute parent_model.



176
177
178
# File 'lib/action_blocks/builders/model_builder.rb', line 176

def parent_model
  @parent_model
end

Returns the value of attribute related_field_id.



176
177
178
# File 'lib/action_blocks/builders/model_builder.rb', line 176

def related_field_id
  @related_field_id
end

Returns the value of attribute related_model.



176
177
178
# File 'lib/action_blocks/builders/model_builder.rb', line 176

def related_model
  @related_model
end

Instance Method Details

#base_match_reqsObject



197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/action_blocks/builders/model_builder.rb', line 197

def base_match_reqs
  if @base_value
    {
    path: [@base_value]
    }
  else
    field_reqs = base_field.match_requirements(@base_model.active_model)
    {
      path: field_reqs[:path]
    }
  end
end

#before_build(parent, base_field, predicate, related_field) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/action_blocks/builders/model_builder.rb', line 181

def before_build(parent, base_field, predicate, related_field)
  if base_field.is_a? Symbol
    @base_model = parent.base_model
    @base_field_id = base_field
    @base_field_key = "field-#{parent.base_model.id}-#{@base_field_id}"
  else
    @base_value = base_field
  end

  @related_model = parent.related_model
  @related_field_id = related_field
  @related_field_key = "field-#{parent.related_model_id}-#{@related_field_id}"

  @predicate = predicate
end

#match_reqsObject



217
218
219
220
221
222
223
# File 'lib/action_blocks/builders/model_builder.rb', line 217

def match_reqs
  {
    base_path: base_match_reqs[:path],
    predicate: @predicate,
    related_path: related_match_reqs[:path]
  }
end


210
211
212
213
214
215
# File 'lib/action_blocks/builders/model_builder.rb', line 210

def related_match_reqs
  field_reqs = related_field.match_requirements()
  {
    path: field_reqs[:path]
  }
end