diff --git a/lib/recommendify/base.rb b/lib/recommendify/base.rb index 620a3fd..b83cc79 100644 --- a/lib/recommendify/base.rb +++ b/lib/recommendify/base.rb @@ -11,7 +11,8 @@ def self.max_neighbors(n=nil) end def self.input_matrix(key, opts) - @@input_matrices[key] = opts + @@input_matrices[self.to_s] = {} if @@input_matrices[self.to_s].nil? + @@input_matrices[self.to_s][key] = opts end def self.input_matrices @@ -19,7 +20,8 @@ def self.input_matrices end def initialize - @input_matrices = Hash[self.class.input_matrices.map{ |key, opts| + @@input_matrices[self.class.to_s] = {} if @@input_matrices[self.class.to_s].nil? + @input_matrices = Hash[self.class.input_matrices[self.class.to_s].map{ |key, opts| opts.merge!(:key => key, :redis_prefix => redis_prefix) [ key, Recommendify::InputMatrix.create(opts) ] }] @@ -83,4 +85,4 @@ def delete_item!(item_id) end end -end \ No newline at end of file +end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index 8d071ee..a3b7ced 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -24,7 +24,8 @@ it "should add an input_matrix by 'key'" do Recommendify::Base.input_matrix(:myinput, :similarity_func => :jaccard) - Recommendify::Base.send(:class_variable_get, :@@input_matrices).keys.should == [:myinput] + Recommendify::Base.send(:class_variable_get, :@@input_matrices).keys.should == [ "Recommendify::Base" ] + Recommendify::Base.send(:class_variable_get, :@@input_matrices)["Recommendify::Base"].keys.should == [:myinput] end it "should retrieve an input_matrix on a new instance" do