Class: RemoteRecord::Config
- Inherits:
-
Object
- Object
- RemoteRecord::Config
- Defined in:
- lib/remote_record/config.rb
Overview
Configuration propagated between remote records and their references. When a new remote reference is initialized, its config is constructed using the defaults of the remote record class and the overrides set when ‘remote_record` is called.
Constant Summary collapse
- OPTIONS =
%i[authorization authorization_source memoize id_field transform].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#block_attr_accessor(attribute, new_value = nil, &block) ⇒ Object
Returns the attribute value if called without args or a block.
-
#initialize(**options) ⇒ Config
constructor
A new instance of Config.
- #merge(config = nil, **overrides) ⇒ Object
- #merge!(config = nil, **overrides) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(**options) ⇒ Config
Returns a new instance of Config.
12 13 14 |
# File 'lib/remote_record/config.rb', line 12 def initialize(**) @options = end |
Class Method Details
.defaults ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/remote_record/config.rb', line 16 def self.defaults new( authorization: '', authorization_source: nil, memoize: true, id_field: :remote_resource_id, transform: [] ) end |
Instance Method Details
#==(other) ⇒ Object
56 57 58 |
# File 'lib/remote_record/config.rb', line 56 def ==(other) other.to_h == @options end |
#block_attr_accessor(attribute, new_value = nil, &block) ⇒ Object
Returns the attribute value if called without args or a block. Otherwise, sets the attribute to the block or value passed.
34 35 36 37 38 39 |
# File 'lib/remote_record/config.rb', line 34 def block_attr_accessor(attribute, new_value = nil, &block) return @options.fetch(attribute) unless block_given? || !new_value.nil? @options[attribute] = block_given? ? block : new_value self end |
#merge(config = nil, **overrides) ⇒ Object
45 46 47 48 |
# File 'lib/remote_record/config.rb', line 45 def merge(config = nil, **overrides) @options.yield_self { || .merge(**(config || {}).to_h) } .yield_self { || .merge(**overrides) } end |
#merge!(config = nil, **overrides) ⇒ Object
50 51 52 53 54 |
# File 'lib/remote_record/config.rb', line 50 def merge!(config = nil, **overrides) @options.merge!(**config.to_h) if config.present? @options.merge!(**overrides) self end |
#to_h ⇒ Object
41 42 43 |
# File 'lib/remote_record/config.rb', line 41 def to_h @options end |