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
-
.get_value_for(record_model, base = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Get the value for the given record using the given options.
-
.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. -
.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).
-
.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.
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.
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, **) GetValue.new(**).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
.
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..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).
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..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.
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 = {}, **) SetValue.new(new_value_by_record_model_and_value_provider, **).call(record_model, base) end |