Class: Waistband::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/waistband/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  options = options.stringify_keys

  @index          = index
  @base_name      = index
  @stringify      = config['stringify']

  @subs = [options['subs']] if options['subs'].present?
  @subs = @subs.flatten     if @subs.is_a?(Array)
end

Instance Attribute Details

#base_nameObject (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_nameObject



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

#configObject



67
68
69
# File 'lib/waistband/index.rb', line 67

def config
  Waistband.config.index @index
end

#config_jsonObject



54
55
56
# File 'lib/waistband/index.rb', line 54

def config_json
  config.except('name', 'stringify').to_json
end

#config_nameObject



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

Returns:

  • (Boolean)


63
64
65
# File 'lib/waistband/index.rb', line 63

def custom_name?
  !!config['name']
end

#envObject



71
72
73
# File 'lib/waistband/index.rb', line 71

def env
  Waistband.config.env
end

#nameObject



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(options = {})
  ::Waistband::Query.new self, options
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