Skip to content

Commit 798b898

Browse files
author
Sean Cribbs
committed
Merge pull request riak-ripple#277 from jcoyne/inheritable_indexes
Indexes should inherit from the superclass
2 parents 3c7a97a + 6010c8f commit 798b898

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/ripple/indexes.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ module Indexes
77
extend ActiveSupport::Concern
88

99
module ClassMethods
10+
11+
def inherited(subclass)
12+
super
13+
subclass.indexes = indexes.dup
14+
end
15+
1016
# Indexes defined on the document.
1117
def indexes
1218
@indexes ||= {}.with_indifferent_access
1319
end
1420

21+
def indexes=(idx)
22+
@indexes = idx
23+
end
24+
1525
def property(key, type, options={})
1626
if indexed = options.delete(:index)
1727
indexes[key] = Index.new(key, type, indexed)

spec/ripple/indexes_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
subject.properties[:name_greeting].should == nil
1717
end
1818
end
19+
context "inherited indexes" do
20+
subject { SubIndexer }
21+
it { should have(5).indexes }
22+
it "should have inherited indexes" do
23+
subject.indexes.keys.should include('age', 'name', 'name_age', 'name_greeting')
24+
end
25+
it "should have indexes defined on the subclass" do
26+
subject.indexes.keys.should include('height')
27+
end
28+
end
1929

2030
context "instance methods" do
2131
before { subject.robject.stub!(:store).and_return(true) }

spec/support/models/indexer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ def name_greeting
2020
"#{name}: Hello!"
2121
end
2222
end
23+
24+
class SubIndexer < Indexer
25+
property :height, String, :index => true
26+
end

0 commit comments

Comments
 (0)