class SelfishAssociations::ScopeReaders::Instance

Attributes

attributes_for_create[R]
attributes_for_find[R]

Public Class Methods

new(instance) click to toggle source
# File lib/selfish_associations/scope_readers/instance.rb, line 6
def initialize(instance)
  @instance = Nilifier.new(instance)
  @attributes_for_find = {}
  @attributes_for_create = {}
end

Public Instance Methods

create_with(conditions) click to toggle source
# File lib/selfish_associations/scope_readers/instance.rb, line 25
def create_with(conditions)
  unnilify(conditions)
  @attributes_for_create.merge!(conditions)
  return self
end
read(scope) click to toggle source
# File lib/selfish_associations/scope_readers/instance.rb, line 12
def read(scope)
  args = scope.arity == 0 ? [] : [@instance]
  instance_exec(*args, &scope)
  return self
end
unnilify(conditions) click to toggle source
# File lib/selfish_associations/scope_readers/instance.rb, line 31
def unnilify(conditions)
  conditions.keys.each do |key|
    conditions[key] = conditions[key].unnilify if conditions[key].respond_to?(:unnilify?)
  end
end
where(conditions) click to toggle source
# File lib/selfish_associations/scope_readers/instance.rb, line 18
def where(conditions)
  unnilify(conditions)
  create_with(conditions)
  @attributes_for_find.merge!(conditions)
  return self
end