class DeepPreloader::Spec

Attributes

association_specs[R]

Public Class Methods

new(association_specs = {}) click to toggle source
# File lib/deep_preloader/spec.rb, line 28
def initialize(association_specs = {})
  @association_specs = association_specs
end
parse(data) click to toggle source
# File lib/deep_preloader/spec.rb, line 6
def self.parse(data)
  case data
  when Array
    data.inject(self.new) do |acc, v|
      acc.merge!(parse(v))
    end
  when Hash
    assoc_specs = data.each_with_object({}) do |(k, v), h|
      h[k.to_sym] = parse(v)
    end
    self.new(assoc_specs)
  when String, Symbol
    self.new({ data.to_sym => nil })
  when DeepPreloader::AbstractSpec
    data
  when nil
    nil
  else
    raise ArgumentError.new("Cannot parse invalid hash preload spec: #{hash.inspect}")
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/deep_preloader/spec.rb, line 54
def ==(other)
  self.class == other.class && self.association_specs == other.association_specs
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/deep_preloader/spec.rb, line 50
def hash
  [self.class, self.association_specs].hash
end
inspect() click to toggle source
# File lib/deep_preloader/spec.rb, line 60
def inspect
  "Spec#{association_specs.inspect}"
end
merge!(other) click to toggle source
# File lib/deep_preloader/spec.rb, line 32
def merge!(other)
  case other
  when nil
    return
  when DeepPreloader::Spec
    other.association_specs.each do |k, v|
      if association_specs[k]
        association_specs[k].merge!(v)
      else
        association_specs[k] = v
      end
    end
  else
    raise ArgumentError.new("Cannot merge #{other.class.name} into #{self.inspect}")
  end
  self
end