Sha256: 02e2d355399086a70f880ed1b19dee285541b3036223e540c5b20724301dd016

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

module RemoteResource
  class ConnectionOptions

    AVAILABLE_OPTIONS = [:site, :headers, :default_headers, :version, :path_prefix, :path_postfix, :collection_prefix, :extension, :collection, :collection_name, :root_element, :json_spec].freeze

    attr_reader :base_class

    def initialize(base_class)
      @base_class = base_class
      self.send :initialize_connection_options
    end

    def merge(options = {})
      options.each do |option, value|
        self.public_send "#{option}=", value
      end and self
    end

    def to_hash
      AVAILABLE_OPTIONS.each_with_object(Hash.new) do |option, hash|
        hash[option] = self.public_send option
      end
    end

    def reload
      initialize_connection_options
    end

    def reload!
      reload and self
    end

    private

    def initialize_connection_options
      AVAILABLE_OPTIONS.each do |option|
        self.class.send :attr_accessor, option
        self.public_send "#{option}=", base_class.public_send(option)
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ddy_remote_resource-1.3.4 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.3.3 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.3.2 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.3.1 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.2.3 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.2.2 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.2.1 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.2.0 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.1.2 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.1.1 lib/remote_resource/connection_options.rb
ddy_remote_resource-1.1.0 lib/remote_resource/connection_options.rb