Class: ActsAsTable::Adapter
- Inherits:
-
Object
- Object
- ActsAsTable::Adapter
- Defined in:
- lib/acts_as_table/adapter.rb
Overview
The "adapter pattern" is a software design pattern that is used to make existing classes work with others without modifying their source code.
ActsAsTable adapter object.
Instance Method Summary collapse
- #classify_for(value_provider, table_name) ⇒ Object
-
#find_or_initialize_by_for(record_model, callee, method_name = :find_or_initialize_by, *args) {|base| ... } ⇒ ActiveRecord::Base
Finds the first record with the given attributes, or creates a record with the attributes if one is not found.
-
#get_value_for(value_provider, base = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Get the value for the given record using the given options.
-
#new_for(record_model, callee, method_name = :new, *args) {|base| ... } ⇒ ActiveRecord::Base
Initializes new record from relation while maintaining the current scope.
-
#set_value_for(value_provider, base = nil, new_value = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Set the new value for the given record using the given options.
- #tableize_for(value_provider, class_name) ⇒ Object
-
#wrap_value_for(value_provider, base = nil, source_value = nil, target_value = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Returns a new ActsAsTable wrapped value object.
Instance Method Details
#classify_for(value_provider, table_name) ⇒ Object
73 74 75 |
# File 'lib/acts_as_table/adapter.rb', line 73 def classify_for(value_provider, table_name) table_name.classify end |
#find_or_initialize_by_for(record_model, callee, method_name = :find_or_initialize_by, *args) {|base| ... } ⇒ ActiveRecord::Base
Finds the first record with the given attributes, or creates a record with the attributes if one is not found.
19 20 21 |
# File 'lib/acts_as_table/adapter.rb', line 19 def find_or_initialize_by_for(record_model, callee, method_name = :find_or_initialize_by, *args, &block) callee.send(method_name, *args, &block) end |
#get_value_for(value_provider, base = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Get the value for the given record using the given options.
43 44 45 |
# File 'lib/acts_as_table/adapter.rb', line 43 def get_value_for(value_provider, base = nil, **) value_provider.get_value(base, **) end |
#new_for(record_model, callee, method_name = :new, *args) {|base| ... } ⇒ ActiveRecord::Base
Initializes new record from relation while maintaining the current scope.
32 33 34 |
# File 'lib/acts_as_table/adapter.rb', line 32 def new_for(record_model, callee, method_name = :new, *args, &block) callee.send(method_name, *args, &block) end |
#set_value_for(value_provider, base = nil, new_value = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Set the new value for the given record using the given options.
55 56 57 |
# File 'lib/acts_as_table/adapter.rb', line 55 def set_value_for(value_provider, base = nil, new_value = nil, **) value_provider.set_value(base, new_value, **) end |
#tableize_for(value_provider, class_name) ⇒ Object
77 78 79 |
# File 'lib/acts_as_table/adapter.rb', line 77 def tableize_for(value_provider, class_name) class_name.tableize end |
#wrap_value_for(value_provider, base = nil, source_value = nil, target_value = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue
Returns a new ActsAsTable wrapped value object.
69 70 71 |
# File 'lib/acts_as_table/adapter.rb', line 69 def wrap_value_for(value_provider, base = nil, source_value = nil, target_value = nil, **) ActsAsTable::ValueProvider::WrappedValue.new(value_provider, base, source_value, target_value, **) end |