class RemoteRecord::Config

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.

Constants

OPTIONS

Public Class Methods

defaults() click to toggle source
# 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
new(**options) click to toggle source
# File lib/remote_record/config.rb, line 12
def initialize(**options)
  @options = options
end

Public Instance Methods

==(other) click to toggle source
# File lib/remote_record/config.rb, line 56
def ==(other)
  other.to_h == @options
end
block_attr_accessor(attribute, new_value = nil, &block) click to toggle source

Returns the attribute value if called without args or a block. Otherwise, sets the attribute to the block or value passed.

# 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) click to toggle source
# File lib/remote_record/config.rb, line 45
def merge(config = nil, **overrides)
  @options.yield_self { |options| options.merge(**(config || {}).to_h) }
          .yield_self { |options| options.merge(**overrides) }
end
merge!(config = nil, **overrides) click to toggle source
# 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() click to toggle source
# File lib/remote_record/config.rb, line 41
def to_h
  @options
end