Class: Waistband::Index
- Inherits:
-
Object
- Object
- Waistband::Index
- Defined in:
- lib/waistband/index.rb
Instance Attribute Summary collapse
-
#base_name ⇒ Object
readonly
Returns the value of attribute base_name.
Instance Method Summary collapse
- #base_config_name ⇒ Object
- #config ⇒ Object
- #config_json ⇒ Object
- #config_name ⇒ Object
- #custom_name? ⇒ Boolean
- #env ⇒ Object
-
#initialize(index, options = {}) ⇒ Index
constructor
A new instance of Index.
- #name ⇒ Object
- #query(options = {}) ⇒ Object
- #store!(key, data) ⇒ Object
Constructor Details
#initialize(index, options = {}) ⇒ Index
Returns a new instance of Index.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/waistband/index.rb', line 18 def initialize(index, = {}) = .stringify_keys @index = index @base_name = index @stringify = config['stringify'] @subs = [['subs']] if ['subs'].present? @subs = @subs.flatten if @subs.is_a?(Array) end |
Instance Attribute Details
#base_name ⇒ Object (readonly)
Returns the value of attribute base_name.
16 17 18 |
# File 'lib/waistband/index.rb', line 16 def base_name @base_name end |
Instance Method Details
#base_config_name ⇒ Object
58 59 60 61 |
# File 'lib/waistband/index.rb', line 58 def base_config_name return config['name'] if config['name'] "#{@base_name}_#{env}" end |
#config ⇒ Object
67 68 69 |
# File 'lib/waistband/index.rb', line 67 def config Waistband.config.index @index end |
#config_json ⇒ Object
54 55 56 |
# File 'lib/waistband/index.rb', line 54 def config_json config.except('name', 'stringify').to_json end |
#config_name ⇒ Object
50 51 52 |
# File 'lib/waistband/index.rb', line 50 def config_name @subs ? "#{base_config_name}__#{@subs.join('_')}" : base_config_name end |
#custom_name? ⇒ Boolean
63 64 65 |
# File 'lib/waistband/index.rb', line 63 def custom_name? !!config['name'] end |
#env ⇒ Object
71 72 73 |
# File 'lib/waistband/index.rb', line 71 def env Waistband.config.env end |
#name ⇒ Object
46 47 48 |
# File 'lib/waistband/index.rb', line 46 def name @subs ? "#{@index}__#{@subs.join('_')}" : @index end |
#query(options = {}) ⇒ Object
42 43 44 |
# File 'lib/waistband/index.rb', line 42 def query( = {}) ::Waistband::Query.new self, end |
#store!(key, data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/waistband/index.rb', line 29 def store!(key, data) # map everything to strings if @stringify original_data = data data = stringify_all data end result = connection.put key, data data = original_data if @stringify result end |