Sha256: 9980bfb33ce0504b076357848d973daea880e7667bac76a6ebf5a64fb0b9c872

Contents?: true

Size: 888 Bytes

Versions: 4

Compression:

Stored size: 888 Bytes

Contents

class Restly::Associations::Base
  extend ActiveSupport::Autoload

  autoload :Loaders
  autoload :Stubs
  autoload :Builders
  autoload :Modifiers
  autoload :Conditionals

  include Loaders
  include Stubs
  include Builders
  include Modifiers
  include Conditionals

  attr_reader :name, :association_class, :namespace, :polymorphic, :options

  def initialize(owner, name, options={})
    @name = name
    @namespace = options.delete(:namespace) || owner.name.gsub(/(::)?\w+$/, '')
    @polymorphic = options.delete(:polymorphic)
    options[:class_name] ||= name.to_s.classify
    @owner = owner
    @association_class = [@namespace, options.delete(:class_name)].select(&:present?).join('::').constantize
    @options = options
  end

  private

  def association_resource_name
    collection? ? association_class.resource_name.pluralize : association_class.resource_name
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restly-0.0.1.alpha.9 lib/restly/associations/base.rb
restly-0.0.1.alpha.8 lib/restly/associations/base.rb
restly-0.0.1.alpha.7 lib/restly/associations/base.rb
restly-0.0.1.alpha.6 lib/restly/associations/base.rb