Sha256: e0c07730c0dd3371d41f3ee7be5ad68620fc4ee5452d1c7d4e274d333766a2ad

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

class Restly::Base::Resource::Specification
  extend ActiveSupport::Autoload

  autoload :Fields
  autoload :MassAssignmentSecurity

  attr_reader :model

  delegate :authorize, :client_token, :path, to: :model

  def initialize(model)
    @model = model
    @specification = HashWithIndifferentAccess.new
    @retry_count = 0
  end

  def accessible_attributes
    @accessible_attributes ||= MassAssignmentSecurity::AccessibleAttributes.new(self)
  end

  def protected_attributes
    @protected_attributes ||= MassAssignmentSecurity::ProtectedAttributes.new(self)
  end

  def active_authorizer
    @active_authorizer ||= MassAssignmentSecurity::DynamicAuthorizer.new(self)
  end

  def fields
    @fields ||= Fields.new(self)
  end

  def [](key)
    reload_specification! unless @specification[key].present?
    @specification[key]
  end

  private

  def reload_specification!
    parsed_response = authorize(client_token).connection.request(:options, path).parsed
    @specification = parsed_response.with_indifferent_access if parsed_response.present?
  rescue OAuth2::Error
    false
  end

  def method_missing(method, *args, &block)
    if self[method]
      self[method]
    else
      @retry_count = 0
      super(method, *args, &block)
    end
  end

  def respond_to_missing?(method, include_private=false)
    model.respond_to?(method)
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
restly-0.0.1.beta.10 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.9 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.6 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.5 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.4 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.3 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.2 lib/restly/base/resource/specification.rb
restly-0.0.1.beta.1 lib/restly/base/resource/specification.rb
restly-0.0.1.alpha.22 lib/restly/base/resource/specification.rb
restly-0.0.1.alpha.19 lib/restly/base/resource/specification.rb
restly-0.0.1.alpha.18 lib/restly/base/resource/specification.rb
restly-0.0.1.alpha.16 lib/restly/base/resource/specification.rb