Module: ActsAsTable::RecordModelClassMethods

Extended by:
ActiveSupport::Concern
Included in:
RowModel
Defined in:
app/models/concerns/acts_as_table/record_model_class_methods.rb

Overview

ActsAsTable record model class methods (concern).

Defined Under Namespace

Classes: FindOrInitializeBy, GetValue, Inject, SetValue

Class Method Summary collapse

Class Method Details

.get_value_for(record_model, base = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue

Get the value for the given record using the given options.

Parameters:

  • record_model (ActsAsTable::RecordModel)
  • base (ActiveRecord::Base, nil) (defaults to: nil)
  • options (Hash<Symbol, Object>)

Options Hash (**options):

  • :default (Boolean)

Returns:

Raises:

  • (ArgumentError)


49
50
51
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 49

def get_value_for(record_model, base = nil, **options)
  GetValue.new(**options).call(record_model, base)
end

.reachable_record_model_for?(source_record_model, target_record_model) ⇒ Boolean

Returns true if the target ActsAsTable record model is reachable from the source ActsAsTable record model. Otherwise, returns false.

Parameters:

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 14

def reachable_record_model_for?(source_record_model, target_record_model)
  Inject.instance.inject(false, source_record_model) { |acc, path, &block|
    # @note Continue until the target ActsAsTable record model is reached.
    acc || (path.options.dig(:data, :target_record_model) == target_record_model) || block.call(acc)
  }
end

.reachable_record_models_for(record_model) ⇒ Array<ActsAsTable::RecordModel>

Returns the ActsAsTable record models that are reachable from the given ActsAsTable record models (in topological order).

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 25

def reachable_record_models_for(record_model)
  Inject.instance.inject([], record_model) { |acc, path, &block|
    # @return [ActsAsTable::RecordModel]
    target_record_model = path.options.dig(:data, :target_record_model)

    # @note Continue until every target ActsAsTable record is reached one or more times.
    if acc.include?(target_record_model)
      acc
    else
      acc << target_record_model

      block.call(acc)
    end
  }
end

.set_value_for(record_model, base = nil, new_value_by_record_model_and_value_provider = {}, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue

Set the new value for the given record using the given options.

Parameters:

Options Hash (**options):

  • :default (Boolean)

Returns:

Raises:

  • (ArgumentError)


62
63
64
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 62

def set_value_for(record_model, base = nil, new_value_by_record_model_and_value_provider = {}, **options)
  SetValue.new(new_value_by_record_model_and_value_provider, **options).call(record_model, base)
end