remocon 0.1.0

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/.gitignore +313 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +70 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +13 -0
  8. data/Gemfile +7 -0
  9. data/Gemfile.lock +72 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +91 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +15 -0
  14. data/bin/get_access_token +11 -0
  15. data/bin/get_access_token.py +18 -0
  16. data/bin/put_by_curl +13 -0
  17. data/bin/setup +8 -0
  18. data/cmd/remocon +6 -0
  19. data/lib/remocon.rb +47 -0
  20. data/lib/remocon/cli.rb +41 -0
  21. data/lib/remocon/command/create_command.rb +48 -0
  22. data/lib/remocon/command/lib/interpreter_helper.rb +44 -0
  23. data/lib/remocon/command/pull_command.rb +66 -0
  24. data/lib/remocon/command/push_command.rb +119 -0
  25. data/lib/remocon/command/validate_command.rb +38 -0
  26. data/lib/remocon/dumper/condition_file_dumper.rb +14 -0
  27. data/lib/remocon/dumper/parameter_file_dumper.rb +22 -0
  28. data/lib/remocon/error/unsupported_type_error.rb +9 -0
  29. data/lib/remocon/error/validation_error.rb +10 -0
  30. data/lib/remocon/interpreter/condition_file_interpreter.rb +32 -0
  31. data/lib/remocon/interpreter/parameter_file_interpreter.rb +60 -0
  32. data/lib/remocon/normalizer/boolean_normalizer.rb +23 -0
  33. data/lib/remocon/normalizer/integer_normalizer.rb +23 -0
  34. data/lib/remocon/normalizer/json_normalizer.rb +20 -0
  35. data/lib/remocon/normalizer/normalizer.rb +33 -0
  36. data/lib/remocon/normalizer/string_normalizer.rb +13 -0
  37. data/lib/remocon/normalizer/type_normalizer_factory.rb +25 -0
  38. data/lib/remocon/normalizer/void_normalizer.rb +9 -0
  39. data/lib/remocon/sorter/condition_sorter.rb +23 -0
  40. data/lib/remocon/sorter/parameter_sorter.rb +24 -0
  41. data/lib/remocon/type.rb +11 -0
  42. data/lib/remocon/util/array.rb +15 -0
  43. data/lib/remocon/util/hash.rb +29 -0
  44. data/lib/remocon/util/string.rb +13 -0
  45. data/lib/remocon/version.rb +5 -0
  46. data/remocon.gemspec +42 -0
  47. data/sample/basketball-b8548/conditions.yml +7 -0
  48. data/sample/basketball-b8548/config.json +67 -0
  49. data/sample/basketball-b8548/etag +1 -0
  50. data/sample/basketball-b8548/parameters.yml +20 -0
  51. metadata +193 -0
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remocon
4
+ class VoidNormalizer < Remocon::Normalizer
5
+ def self.respond_symbol
6
+ Remocon::Type::VOID
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remocon
4
+ module ConditionSorter
5
+ CONDITION_KEYS = %i[name expression tagColor]
6
+
7
+ def sort_conditions(conditions)
8
+ conditions
9
+ .sort_by { |e| e[:name] }
10
+ .map do |e|
11
+ arr = e.sort do |(a, _), (b, _)|
12
+ if !CONDITION_KEYS.include?(a) && !CONDITION_KEYS.include?(b)
13
+ a <=> b
14
+ else
15
+ (CONDITION_KEYS.index(a) || 10000) <=> (CONDITION_KEYS.index(b) || 10000)
16
+ end
17
+ end
18
+
19
+ arr.each_with_object({}) { |(k, v), h| h[k] = v }.with_indifferent_access
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remocon
4
+ module ParameterSorter
5
+ PARAMETER_KEYS = %i[description value file normalizer conditions options]
6
+
7
+ def sort_parameters(parameters)
8
+ arr = parameters.sort.map do |k, v|
9
+ hash_arr = v.sort { |(a, _), (b, _)| PARAMETER_KEYS.index(a) <=> PARAMETER_KEYS.index(b) }
10
+ .map do |k, v|
11
+ {
12
+ k => k.to_sym == :conditions ? sort_parameters(v) : v
13
+ }
14
+ end
15
+
16
+ {
17
+ k => hash_arr.each_with_object({}) { |hash, acc| acc.merge!(hash) }
18
+ }
19
+ end
20
+
21
+ arr.each_with_object({}) { |hash, acc| acc.merge!(hash) }.with_indifferent_access
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remocon
4
+ module Type
5
+ STRING = :string
6
+ INTEGER = :integer
7
+ BOOLEAN = :boolean
8
+ JSON = :json
9
+ VOID = :void
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Array
4
+ def stringify_values
5
+ map do |e|
6
+ if e.is_a?(Hash)
7
+ e.stringify_values
8
+ elsif e.is_a?(Array)
9
+ e.stringify_values
10
+ else
11
+ e.to_s
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ def skip_nil_values
5
+ dup.compact.each_with_object({}) do |(k, v), acc|
6
+ next unless v
7
+ acc[k] = case v
8
+ when Hash
9
+ v.skip_nil_values
10
+ when Array
11
+ v.compact
12
+ else
13
+ v
14
+ end
15
+ end
16
+ end
17
+
18
+ def stringify_values
19
+ self.deep_merge(self) do |_, _, v|
20
+ if v.is_a?(Hash)
21
+ v.stringify_values
22
+ elsif v.is_a?(Array)
23
+ v.stringify_values
24
+ else
25
+ v.to_s
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ def to_integer
5
+ Integer(self)
6
+ end
7
+
8
+ def to_boolean
9
+ return true if self == "true"
10
+ return false if self == "false"
11
+ raise ArgumentError, 'String cannot be converted to Boolean'
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remocon
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,42 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'remocon/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'remocon'
10
+ spec.version = Remocon::VERSION
11
+ spec.authors = ['Jumpei Matsuda']
12
+ spec.email = ['jmatsu.drm@gmail.com']
13
+
14
+ spec.summary = 'YAML-based firebase remote config manager'
15
+ spec.description = "This gem manages RemoteConfig's key-values based on YAML configuration."
16
+ spec.homepage = 'https://github.com/jmatsu/remocon'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
23
+ else
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
26
+ end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ end
31
+ spec.bindir = 'cmd'
32
+ spec.executables = spec.files.grep(%r{^cmd/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_dependency 'thor'
36
+ spec.add_dependency 'activesupport'
37
+ spec.add_development_dependency 'bundler', '~> 1.16'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'pry'
41
+ spec.add_development_dependency 'rubocop'
42
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ - name: condition1
3
+ expression: device.os == 'ios'
4
+ tagColor: INDIGO
5
+ - name: zxczx
6
+ expression: device.os == 'ios'
7
+ tagColor: CYAN
@@ -0,0 +1,67 @@
1
+ {
2
+ "conditions": [
3
+ {
4
+ "name": "condition1",
5
+ "expression": "device.os == 'ios'",
6
+ "tagColor": "INDIGO"
7
+ },
8
+ {
9
+ "name": "zxczx",
10
+ "expression": "device.os == 'ios'",
11
+ "tagColor": "CYAN"
12
+ }
13
+ ],
14
+ "parameters": {
15
+ "key1": {
16
+ "defaultValue": {
17
+ "value": "100",
18
+ "conditions": {
19
+ "condition1": {
20
+ "value": "200"
21
+ },
22
+ "zxczx": {
23
+ "value": "100"
24
+ }
25
+ }
26
+ },
27
+ "conditionalValues": {
28
+ "condition1": {
29
+ "value": "200"
30
+ },
31
+ "zxczx": {
32
+ "value": "100"
33
+ }
34
+ }
35
+ },
36
+ "key2": {
37
+ "defaultValue": {
38
+ "value": "123"
39
+ }
40
+ },
41
+ "key3": {
42
+ "defaultValue": {
43
+ "value": "true"
44
+ }
45
+ },
46
+ "key4": {
47
+ "defaultValue": {
48
+ "value": "false"
49
+ }
50
+ },
51
+ "key5": {
52
+ "defaultValue": {
53
+ "value": "xxxx"
54
+ }
55
+ },
56
+ "key6": {
57
+ "defaultValue": {
58
+ "value": "{\"value\":\"xxxx\"}"
59
+ }
60
+ },
61
+ "key7": {
62
+ "defaultValue": {
63
+ "value": "{\"x1\":\"x1\",\"x2\":\"x2\"}"
64
+ }
65
+ }
66
+ }
67
+ }
@@ -0,0 +1 @@
1
+ etag-298187264474-16
@@ -0,0 +1,20 @@
1
+ ---
2
+ key1:
3
+ value: '100'
4
+ conditions:
5
+ condition1:
6
+ value: '200'
7
+ zxczx:
8
+ value: '100'
9
+ key2:
10
+ value: '123'
11
+ key3:
12
+ value: 'true'
13
+ key4:
14
+ value: 'false'
15
+ key5:
16
+ value: xxxx
17
+ key6:
18
+ value: '{"value":"xxxx"}'
19
+ key7:
20
+ value: '{"x1":"x1","x2":"x2"}'
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remocon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jumpei Matsuda
8
+ autorequire:
9
+ bindir: cmd
10
+ cert_chain: []
11
+ date: 2018-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: This gem manages RemoteConfig's key-values based on YAML configuration.
112
+ email:
113
+ - jmatsu.drm@gmail.com
114
+ executables:
115
+ - remocon
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".envrc"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-version"
124
+ - ".travis.yml"
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/get_access_token
132
+ - bin/get_access_token.py
133
+ - bin/put_by_curl
134
+ - bin/setup
135
+ - cmd/remocon
136
+ - lib/remocon.rb
137
+ - lib/remocon/cli.rb
138
+ - lib/remocon/command/create_command.rb
139
+ - lib/remocon/command/lib/interpreter_helper.rb
140
+ - lib/remocon/command/pull_command.rb
141
+ - lib/remocon/command/push_command.rb
142
+ - lib/remocon/command/validate_command.rb
143
+ - lib/remocon/dumper/condition_file_dumper.rb
144
+ - lib/remocon/dumper/parameter_file_dumper.rb
145
+ - lib/remocon/error/unsupported_type_error.rb
146
+ - lib/remocon/error/validation_error.rb
147
+ - lib/remocon/interpreter/condition_file_interpreter.rb
148
+ - lib/remocon/interpreter/parameter_file_interpreter.rb
149
+ - lib/remocon/normalizer/boolean_normalizer.rb
150
+ - lib/remocon/normalizer/integer_normalizer.rb
151
+ - lib/remocon/normalizer/json_normalizer.rb
152
+ - lib/remocon/normalizer/normalizer.rb
153
+ - lib/remocon/normalizer/string_normalizer.rb
154
+ - lib/remocon/normalizer/type_normalizer_factory.rb
155
+ - lib/remocon/normalizer/void_normalizer.rb
156
+ - lib/remocon/sorter/condition_sorter.rb
157
+ - lib/remocon/sorter/parameter_sorter.rb
158
+ - lib/remocon/type.rb
159
+ - lib/remocon/util/array.rb
160
+ - lib/remocon/util/hash.rb
161
+ - lib/remocon/util/string.rb
162
+ - lib/remocon/version.rb
163
+ - remocon.gemspec
164
+ - sample/basketball-b8548/conditions.yml
165
+ - sample/basketball-b8548/config.json
166
+ - sample/basketball-b8548/etag
167
+ - sample/basketball-b8548/parameters.yml
168
+ homepage: https://github.com/jmatsu/remocon
169
+ licenses:
170
+ - MIT
171
+ metadata:
172
+ allowed_push_host: https://rubygems.org
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.7.3
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: YAML-based firebase remote config manager
193
+ test_files: []