Skip to content

Commit

Permalink
Merge pull request #314 from mikeyhogarth/refactor/extract-method-on-…
Browse files Browse the repository at this point in the history
…prefix

Refactor/extract method on prefix
  • Loading branch information
pyromaniac committed Jan 23, 2016
2 parents 2717009 + 159ced4 commit 300467f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/chewy/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ class Index
#
def self.index_name(suggest = nil)
if suggest
@index_name = build_index_name(suggest, prefix: Chewy.configuration[:prefix])
@index_name = build_index_name(suggest, prefix: default_prefix)
else
@index_name ||= begin
build_index_name(
name.sub(/Index\Z/, '').demodulize.underscore,
prefix: Chewy.configuration[:prefix]
prefix: default_prefix
) if name
end
end
@index_name or raise UndefinedIndex
end

# Prefix to use
#
def self.default_prefix
Chewy.configuration[:prefix]
end

# Defines type for the index. Arguments depends on adapter used. For
# ActiveRecord you can pass model or scope and options
#
Expand Down
5 changes: 5 additions & 0 deletions spec/chewy/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
end
end

describe '.default_prefix' do
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
specify { expect(Class.new(Chewy::Index).default_prefix).to eq('testing') }
end

describe '.define_type' do
specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) }

Expand Down

0 comments on commit 300467f

Please sign in to comment.