Class: Almicube::Selector::HasManySelector

Inherits:
Base
  • Object
show all
Defined in:
lib/almicube/selector/has_many_selector.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#class_name

Attributes included from Cog

#ranking

Instance Method Summary collapse

Methods inherited from Base

#data_provider?

Methods included from Cog

#active?, #after_aggregate

Constructor Details

#initialize(options = {}) ⇒ HasManySelector

Returns a new instance of HasManySelector.



7
8
9
10
11
12
# File 'lib/almicube/selector/has_many_selector.rb', line 7

def initialize(options={})
  super(options)

  @target = options[:target]
  @association_name = options[:association_name]
end

Instance Attribute Details

#association_nameObject (readonly)

Returns the value of attribute association_name.



5
6
7
# File 'lib/almicube/selector/has_many_selector.rb', line 5

def association_name
  @association_name
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/almicube/selector/has_many_selector.rb', line 5

def target
  @target
end

Instance Method Details

#before_aggregateObject



22
23
24
25
26
# File 'lib/almicube/selector/has_many_selector.rb', line 22

def before_aggregate
  records.map{ |r| r.to_param }.each do |i|
    Config.config.connection.zadd(interstore_key, 0, i)
  end
end

#interstoreObject



28
29
30
# File 'lib/almicube/selector/has_many_selector.rb', line 28

def interstore
  interstore_key
end

#labelObject



18
19
20
# File 'lib/almicube/selector/has_many_selector.rb', line 18

def label
  "#{target.class.to_s.underscore}-#{target.to_param}"
end

#recordsObject



14
15
16
# File 'lib/almicube/selector/has_many_selector.rb', line 14

def records
  target.send(association_name)
end