Class: SpecStore

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

Instance Method Summary collapse

Constructor Details

#initialize(specs_json) ⇒ SpecStore

Returns a new instance of SpecStore.



5
6
7
8
9
10
11
12
# File 'lib/spec_store.rb', line 5

def initialize(specs_json)
  @last_sync_time = 0
  @store = {
    :gates => {},
    :configs => {},
  }
  process(specs_json)
end

Instance Method Details

#get_config(config_name) ⇒ Object



46
47
48
49
# File 'lib/spec_store.rb', line 46

def get_config(config_name)
  return nil unless has_config?(config_name)
  @store[:configs][config_name]
end

#get_gate(gate_name) ⇒ Object



41
42
43
44
# File 'lib/spec_store.rb', line 41

def get_gate(gate_name)
  return nil unless has_gate?(gate_name)
  @store[:gates][gate_name]
end

#has_config?(config_name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/spec_store.rb', line 37

def has_config?(config_name)
  return @store[:configs].key?(config_name)
end

#has_gate?(gate_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/spec_store.rb', line 33

def has_gate?(gate_name)
  return @store[:gates].key?(gate_name)
end

#process(specs_json) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spec_store.rb', line 14

def process(specs_json)
  if specs_json.nil?
    return
  end

  @last_sync_time = specs_json['time'] || @last_sync_time
  return unless specs_json['has_updates'] == true &&
    !specs_json['feature_gates'].nil? &&
    !specs_json['dynamic_configs'].nil?

  @store = {
    :gates => {},
    :configs => {},
  }

  specs_json['feature_gates'].map{|gate|  @store[:gates][gate['name']] = gate }
  specs_json['dynamic_configs'].map{|config|  @store[:configs][config['name']] = config }
end