From dbd6669002b26f2c81c1c138d966fe36ae6314a9 Mon Sep 17 00:00:00 2001 From: Mikey Hogarth Date: Wed, 20 Jan 2016 08:26:16 +0000 Subject: [PATCH 1/2] Extract-method on prefix --- lib/chewy/index.rb | 8 +++++++- spec/chewy/index_spec.rb | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/chewy/index.rb b/lib/chewy/index.rb index f5ff4348f..e46c167af 100644 --- a/lib/chewy/index.rb +++ b/lib/chewy/index.rb @@ -30,7 +30,7 @@ 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: prefix) else @index_name ||= begin build_index_name( @@ -42,6 +42,12 @@ def self.index_name(suggest = nil) @index_name or raise UndefinedIndex end + # Prefix to use + # + def self.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 # diff --git a/spec/chewy/index_spec.rb b/spec/chewy/index_spec.rb index 10282ce79..e2c7ef1c1 100644 --- a/spec/chewy/index_spec.rb +++ b/spec/chewy/index_spec.rb @@ -68,6 +68,11 @@ end end + describe '.prefix' do + before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) } + specify { expect(Class.new(Chewy::Index).prefix).to eq('testing') } + end + describe '.define_type' do specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) } From 159ced45fde5edef4ab40b27b2defa2943cf7a3d Mon Sep 17 00:00:00 2001 From: Mikey Hogarth Date: Wed, 20 Jan 2016 08:32:44 +0000 Subject: [PATCH 2/2] alter name --- lib/chewy/index.rb | 6 +++--- spec/chewy/index_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/chewy/index.rb b/lib/chewy/index.rb index e46c167af..95cb8378d 100644 --- a/lib/chewy/index.rb +++ b/lib/chewy/index.rb @@ -30,12 +30,12 @@ class Index # def self.index_name(suggest = nil) if suggest - @index_name = build_index_name(suggest, prefix: 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 @@ -44,7 +44,7 @@ def self.index_name(suggest = nil) # Prefix to use # - def self.prefix + def self.default_prefix Chewy.configuration[:prefix] end diff --git a/spec/chewy/index_spec.rb b/spec/chewy/index_spec.rb index e2c7ef1c1..a03453351 100644 --- a/spec/chewy/index_spec.rb +++ b/spec/chewy/index_spec.rb @@ -68,9 +68,9 @@ end end - describe '.prefix' do + describe '.default_prefix' do before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) } - specify { expect(Class.new(Chewy::Index).prefix).to eq('testing') } + specify { expect(Class.new(Chewy::Index).default_prefix).to eq('testing') } end describe '.define_type' do