remocon 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f0c28fa84a9323c0c1d867d81d7b8a13b676774
4
- data.tar.gz: 2637bbbec4410f90cfc2d086b55fc6340890c6ed
3
+ metadata.gz: ba22438936a77cbe485e6bb7ae72b0f059d5f3fa
4
+ data.tar.gz: 9ff3bbda91e0d622d99aef839558b6b834475a25
5
5
  SHA512:
6
- metadata.gz: 3ac73ff7a2316cad4ce51836741d753b7c023bd8413c36e4c8c7bbb707a4fa7f63e8facccf2386bab7216686e824e977e61f67eaf75d329540f033fddf1319ba
7
- data.tar.gz: be5f1b03a2967c35ef96be01d23dd84eb8ad5392b99bbdaa95268f39eb687dc0e84a9d140e11b0b0960473714eec132b832706802c81906b5f382d7b55b41fbd
6
+ metadata.gz: 49795b41a9351d77fffe996ae612a8ce804bdc0e5610dabf32b13cc1e602dc71ad1baaf52a0041f62ea7f043f304b8bc683bacaad30ae37dadcdef9b103aa234
7
+ data.tar.gz: 456bbde3f2091231fd43bbfcc38c2c605991f6586ad1edca5f4c72dfa60443e92965a29608fc8311c67f8dc89f6cd599b3dd9c5cc49a3772c1d1562604d020bf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remocon (0.4.1)
4
+ remocon (0.4.2)
5
5
  activesupport
6
6
  googleauth
7
7
  thor
data/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  # Remocon
4
4
 
5
- *remocon* is a CLI for Firebase Remote Config via its REST API.
6
- Conditions and parameters are managed by YAML files.
5
+ *remocon* is a CLI for Firebase Remote Config via its REST API. Conditions and parameters are managed by YAML files.
6
+ The goal of this gem is Remote Config as a Code. :)
7
7
 
8
- *This is still in beta. A diff mode should be supported when managing configs heavily.*
8
+ *Now conditions cannot be updated via API so that you can modify only parameters.*
9
+
10
+ If you'd like to use this on CircleCI, you can use https://github.com/jmatsu/remocon-starter-kit .
9
11
 
10
12
  ## Usage
11
13
 
@@ -41,7 +43,7 @@ FIREBASE_PROJECT_ID and REMOTE_CONFIG_ACCESS_TOKEN are supported but they are de
41
43
 
42
44
  ### Edit configs on your local
43
45
 
44
- Condition definitions and parameter definitions are separated. You should modify these files.
46
+ Condition definitions and parameter definitions are separated. You need to modify these files.
45
47
 
46
48
  *parameters.yml*
47
49
 
@@ -2,9 +2,6 @@
2
2
 
3
3
  module Remocon
4
4
  module InterpreterHelper
5
- include Remocon::ConditionSorter
6
- include Remocon::ParameterSorter
7
-
8
5
  def cmd_opts
9
6
  raise NotImplementedError
10
7
  end
@@ -25,7 +22,7 @@ module Remocon
25
22
  end
26
23
 
27
24
  def parameter_hash
28
- @parameter_hash ||= sort_parameters(read_parameters.first)
25
+ @parameter_hash ||= read_parameters.first
29
26
  end
30
27
 
31
28
  def read_conditions
@@ -36,7 +33,7 @@ module Remocon
36
33
  end
37
34
 
38
35
  def condition_array
39
- @condition_array ||= sort_conditions(read_conditions.first)
36
+ @condition_array ||= read_conditions.first
40
37
  end
41
38
 
42
39
  def condition_names
@@ -30,6 +30,8 @@ module Remocon
30
30
  end
31
31
 
32
32
  include Remocon::InterpreterHelper
33
+ include Remocon::ConditionSorter
34
+ include Remocon::ParameterSorter
33
35
 
34
36
  attr_reader :config, :cmd_opts, :left
35
37
 
@@ -2,22 +2,20 @@
2
2
 
3
3
  module Remocon
4
4
  module ConditionSorter
5
- CONDITION_KEYS = %i(name expression tagColor).freeze
5
+ CONDITION_KEYS = %w(name expression tagColor).freeze
6
+
7
+ def comparator_of_condition_keys(left, right)
8
+ (CONDITION_KEYS.index(left) || 10_000) <=> (CONDITION_KEYS.index(right) || 10_000)
9
+ end
6
10
 
7
11
  def sort_conditions(conditions)
8
12
  conditions
9
- .map(&:symbolize_keys)
10
- .sort_by { |e| e[:name] }
13
+ .sort_by { |e| e["name"] || e[:name] }
11
14
  .map do |e|
12
- arr = e.sort do |(a, _), (b, _)|
13
- if !CONDITION_KEYS.include?(a) && !CONDITION_KEYS.include?(b)
14
- a <=> b
15
- else
16
- (CONDITION_KEYS.index(a) || 10_000) <=> (CONDITION_KEYS.index(b) || 10_000)
17
- end
18
- end
19
-
20
- arr.each_with_object({}) { |(k, v), h| h[k] = v }.with_indifferent_access
15
+ e.stringify_keys
16
+ .sort { |(a, _), (b, _)| comparator_of_condition_keys(a, b) }
17
+ .each_with_object({}) { |(k, v), acc| acc[k] = v }
18
+ .with_indifferent_access
21
19
  end
22
20
  end
23
21
  end
@@ -2,23 +2,39 @@
2
2
 
3
3
  module Remocon
4
4
  module ParameterSorter
5
- PARAMETER_KEYS = %i(description value file normalizer conditions options).freeze
5
+ PARAMETER_KEYS = %w(description value file normalizer conditions options).freeze
6
+
7
+ def comparator_of_parameter_keys(left, right)
8
+ PARAMETER_KEYS.index(left) <=> PARAMETER_KEYS.index(right)
9
+ end
6
10
 
7
11
  def sort_parameters(parameters)
8
- arr = parameters.sort.map do |k, v|
9
- hash_arr = v.symbolize_keys.sort { |(a, _), (b, _)| PARAMETER_KEYS.index(a) <=> PARAMETER_KEYS.index(b) }
10
- .map do |k1, v1|
11
- {
12
- k1 => k1.to_sym == :conditions ? sort_parameters(v1) : v1
13
- }
12
+ params = parameters.with_indifferent_access
13
+
14
+ params.keys.sort.each_with_object({}) do |key, acc|
15
+ param = params[key]
16
+
17
+ acc[key] = param
18
+ .stringify_keys
19
+ .sort { |(a, _), (b, _)| comparator_of_parameter_keys(a, b) }
20
+ .each_with_object({}) do |(inside_key, _), inside_acc|
21
+ if inside_key == "conditions"
22
+ inside_acc[inside_key] = sort_conditions_of_parameters(param[inside_key])
23
+ else
24
+ inside_acc[inside_key] = param[inside_key]
25
+ end
14
26
  end
27
+ end.with_indifferent_access
28
+ end
15
29
 
16
- {
17
- k => hash_arr.each_with_object({}) { |hash, acc| acc.merge!(hash) }
18
- }
30
+ def sort_conditions_of_parameters(conditions)
31
+ conditions.with_indifferent_access.to_a.each_with_object({}) do |(k, v), acc|
32
+ acc[k] = v.stringify_keys
33
+ .sort { |(a, _), (b, _)| comparator_of_parameter_keys(a, b) }
34
+ .each_with_object({}) do |(inside_key, _), inside_acc|
35
+ inside_acc[inside_key] = v[inside_key]
36
+ end
19
37
  end
20
-
21
- arr.each_with_object({}) { |hash, acc| acc.merge!(hash) }.with_indifferent_access
22
38
  end
23
39
  end
24
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Remocon
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remocon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jumpei Matsuda
8
8
  autorequire:
9
9
  bindir: cmd
10
10
  cert_chain: []
11
- date: 2018-08-14 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport