ruby_fly 0.21.0 → 0.22.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce6c9fb1aa9bbacae200d0037f7dbb99064703b58a019e32308f08ab8e160ab4
4
- data.tar.gz: 0a6b6b658741007f816911ca5549ea7a4d5f1514fe96d6c7835239e94b088b23
3
+ metadata.gz: 02aacdb7d522ae012be3b184467363d8e79b465d97cde5435e1ebd3ad8b6b70a
4
+ data.tar.gz: 686badf9bf8a842165f6ebc8f83d2c9ce206b09c17f40c95fff3eb6a79364c7e
5
5
  SHA512:
6
- metadata.gz: ffb252244ea47ae0ad3bd40e42caa494d46fdeb9259b47246887636636b3974c846fea64ef4edda7e327e51dd3089bf00c935978403b968875a0756b38f398d2
7
- data.tar.gz: 62d49734219de4ad15216572aee7020a98647c28bc00200f4322caaf5d75919bd310e2c46adfc48aee75db2c4f7c1800d2cf45134636a7aa372292ddc6597829
6
+ metadata.gz: 2103ce38418548a2e4db3a309be0bbe37f9670eea98e366862faae11c9c5b8e5ed914d3dd4810207173c37f117d48e529da59b977cfdd80b7f51ec13665be7cd
7
+ data.tar.gz: 800e196b5efb033bdb6401437750e3bc6a756cf4dc7d55aa4849c94f66d3fba7b67230187a7e64e73618a785d572b571d4cbbb7ad959911ed04f36bd4eefdadd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_fly (0.21.0)
4
+ ruby_fly (0.22.0.pre.1)
5
5
  lino (>= 1.5)
6
6
 
7
7
  GEM
@@ -19,20 +19,25 @@ GEM
19
19
  concurrent-ruby (1.1.7)
20
20
  diff-lcs (1.4.4)
21
21
  excon (0.78.1)
22
- faraday (1.2.0)
22
+ fakefs (1.3.1)
23
+ faker (2.15.1)
24
+ i18n (>= 1.6, < 2)
25
+ faraday (1.3.0)
26
+ faraday-net_http (~> 1.0)
23
27
  multipart-post (>= 1.2, < 3)
24
28
  ruby2_keywords
29
+ faraday-net_http (1.0.0)
25
30
  gem-release (2.2.0)
26
31
  hamster (3.0.0)
27
32
  concurrent-ruby (~> 1.0)
28
- i18n (1.8.5)
33
+ i18n (1.8.6)
29
34
  concurrent-ruby (~> 1.0)
30
- lino (1.5.0)
35
+ lino (1.7.0)
31
36
  hamster (~> 3.0)
32
37
  open4 (~> 1.3)
33
38
  minitest (5.14.2)
34
39
  multipart-post (2.1.1)
35
- octokit (4.19.0)
40
+ octokit (4.20.0)
36
41
  faraday (>= 0.9)
37
42
  sawyer (~> 0.8.0, >= 0.5.3)
38
43
  open4 (1.3.4)
@@ -43,10 +48,10 @@ GEM
43
48
  excon (~> 0.72)
44
49
  rake_factory (~> 0.23)
45
50
  sshkey (~> 2.0)
46
- rake_factory (0.27.0)
51
+ rake_factory (0.29.0)
47
52
  activesupport (>= 4)
48
53
  rake (~> 13.0)
49
- rake_github (0.5.0)
54
+ rake_github (0.7.0)
50
55
  colored2 (~> 3.1)
51
56
  octokit (~> 4.16)
52
57
  rake_factory (~> 0.23)
@@ -54,7 +59,7 @@ GEM
54
59
  rake_gpg (0.14.0)
55
60
  rake_factory (>= 0.23, < 1)
56
61
  ruby_gpg2 (>= 0.6, < 1)
57
- rake_ssh (0.4.0)
62
+ rake_ssh (0.6.0)
58
63
  colored2 (~> 3.1)
59
64
  rake_factory (~> 0.23)
60
65
  sshkey (~> 2.0)
@@ -62,17 +67,17 @@ GEM
62
67
  rspec-core (~> 3.10.0)
63
68
  rspec-expectations (~> 3.10.0)
64
69
  rspec-mocks (~> 3.10.0)
65
- rspec-core (3.10.0)
70
+ rspec-core (3.10.1)
66
71
  rspec-support (~> 3.10.0)
67
- rspec-expectations (3.10.0)
72
+ rspec-expectations (3.10.1)
68
73
  diff-lcs (>= 1.2.0, < 2.0)
69
74
  rspec-support (~> 3.10.0)
70
- rspec-mocks (3.10.0)
75
+ rspec-mocks (3.10.1)
71
76
  diff-lcs (>= 1.2.0, < 2.0)
72
77
  rspec-support (~> 3.10.0)
73
- rspec-support (3.10.0)
78
+ rspec-support (3.10.1)
74
79
  ruby2_keywords (0.0.2)
75
- ruby_gpg2 (0.6.0)
80
+ ruby_gpg2 (0.8.0)
76
81
  lino (>= 1.5)
77
82
  sawyer (0.8.2)
78
83
  addressable (>= 2.3.5)
@@ -87,6 +92,8 @@ PLATFORMS
87
92
 
88
93
  DEPENDENCIES
89
94
  bundler (~> 2.1)
95
+ fakefs (~> 1.3)
96
+ faker (~> 2.15)
90
97
  gem-release (~> 2.0)
91
98
  rake (~> 13.0)
92
99
  rake_circle_ci (~> 0.9)
@@ -1,5 +1,6 @@
1
1
  require 'ruby_fly/version'
2
2
  require 'ruby_fly/commands'
3
+ require 'ruby_fly/rc'
3
4
 
4
5
  module RubyFly
5
6
  class << self
@@ -0,0 +1,204 @@
1
+ require 'fileutils'
2
+
3
+ module RubyFly
4
+ class RC
5
+ module Conversions
6
+ def self.symbolize_keys(hash)
7
+ hash.inject({}) { |result, (key, value)|
8
+ new_key = case key
9
+ when String then
10
+ key.to_sym
11
+ else
12
+ key
13
+ end
14
+ new_value = case value
15
+ when Hash then
16
+ symbolize_keys(value)
17
+ else
18
+ value
19
+ end
20
+ result[new_key] = new_value
21
+ result
22
+ }
23
+ end
24
+
25
+ def self.stringify_keys(hash)
26
+ hash.inject({}) { |result, (key, value)|
27
+ new_key = case key
28
+ when Symbol then
29
+ key.to_s
30
+ else
31
+ key
32
+ end
33
+ new_value = case value
34
+ when Hash then
35
+ stringify_keys(value)
36
+ else
37
+ value
38
+ end
39
+ result[new_key] = new_value
40
+ result
41
+ }
42
+ end
43
+ end
44
+
45
+ class TargetAlreadyPresentError < StandardError
46
+ def initialize(target_name)
47
+ super("Target with name: #{target_name} already present in RC.")
48
+ end
49
+ end
50
+
51
+ class TargetNotPresentError < StandardError
52
+ def initialize(target_name)
53
+ super("Target with name: #{target_name} not present in RC.")
54
+ end
55
+ end
56
+
57
+ class Target
58
+ attr_reader :name, :api, :team, :token
59
+ attr_writer :api, :team, :token
60
+
61
+ def self.clone(target, overrides = {})
62
+ if target.nil?
63
+ return target
64
+ end
65
+ Target.new(
66
+ name: overrides[:name] || target.name,
67
+ api: overrides[:api] || target.api,
68
+ team: overrides[:team] || target.team,
69
+ token: overrides[:token] || target.token)
70
+ end
71
+
72
+ def initialize(parameters)
73
+ @name = parameters[:name]
74
+ @api = parameters[:api]
75
+ @team = parameters[:team]
76
+ @token = parameters[:token]
77
+ end
78
+
79
+ def bearer_token=(value)
80
+ @token = {
81
+ type: 'bearer',
82
+ value: value
83
+ }
84
+ end
85
+
86
+ def bearer_token
87
+ @token[:type] == 'bearer' ?
88
+ @token[:value] :
89
+ nil
90
+ end
91
+
92
+ def encode_with(coder)
93
+ coder.represent_map(
94
+ nil,
95
+ RubyFly::RC::Conversions.stringify_keys({
96
+ api: @api,
97
+ team: @team.to_s,
98
+ token: @token
99
+ }))
100
+ end
101
+
102
+ def ==(other)
103
+ other.class == self.class && other.state == state
104
+ end
105
+
106
+ def eql?(other)
107
+ self == other
108
+ end
109
+
110
+ def hash
111
+ state.hash
112
+ end
113
+
114
+ protected
115
+
116
+ def state
117
+ [@name, @api, @team, @token]
118
+ end
119
+ end
120
+
121
+ def self.load(options)
122
+ home = options[:home] || ENV['HOME']
123
+ name = options[:name] || '.flyrc'
124
+ path = File.join(home, name)
125
+
126
+ contents = options[:contents] ||
127
+ (File.exist?(path) ?
128
+ RubyFly::RC::Conversions.symbolize_keys(YAML.load_file(path)) :
129
+ {})
130
+ targets = File.exist?(path) ?
131
+ contents[:targets].map { |n, t| Target.new(t.merge(name: n)) } :
132
+ []
133
+
134
+ RubyFly::RC.new(
135
+ home: home,
136
+ name: name,
137
+ targets: targets)
138
+ end
139
+
140
+ def initialize(options)
141
+ @home = options[:home] || ENV['HOME']
142
+ @name = options[:name] || '.flyrc'
143
+ @targets = options[:targets].inject({}) do |acc, target|
144
+ acc.merge(target.name => target)
145
+ end
146
+ end
147
+
148
+ def targets
149
+ @targets.values
150
+ end
151
+
152
+ def find_target(target_name)
153
+ Target.clone(@targets[target_name.to_sym])
154
+ end
155
+
156
+ def has_target?(target_name)
157
+ @targets.has_key?(target_name)
158
+ end
159
+
160
+ def add_target(target)
161
+ if has_target?(target.name)
162
+ raise TargetAlreadyPresentError.new(target.name)
163
+ end
164
+ @targets[target.name] = target
165
+ end
166
+
167
+ def update_target(target_name, &block)
168
+ unless has_target?(target_name)
169
+ raise TargetNotPresentError.new(target_name)
170
+ end
171
+ mutable_target = find_target(target_name)
172
+ block.call(mutable_target)
173
+ updated_target = Target.clone(mutable_target, name: target_name)
174
+ @targets[target_name] = updated_target
175
+ end
176
+
177
+ def rename_target(old_target_name, new_target_name)
178
+ old_target = find_target(old_target_name)
179
+ new_target = Target.clone(old_target, name: new_target_name)
180
+ remove_target(old_target_name)
181
+ add_target(new_target)
182
+ end
183
+
184
+ def remove_target(target_name)
185
+ unless has_target?(target_name)
186
+ raise TargetNotPresentError.new(target_name)
187
+ end
188
+ @targets.delete(target_name)
189
+ end
190
+
191
+ def to_yaml
192
+ RubyFly::RC::Conversions
193
+ .stringify_keys({targets: @targets})
194
+ .to_yaml
195
+ end
196
+
197
+ def write!
198
+ FileUtils.mkdir_p(@home)
199
+ File.open(File.join(@home, @name), 'w') do |file|
200
+ file.write(to_yaml)
201
+ end
202
+ end
203
+ end
204
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyFly
2
- VERSION = '0.21.0'
2
+ VERSION = '0.22.0.pre.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_fly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lino
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fakefs
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faker
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.15'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.15'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: gem-release
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +187,7 @@ files:
159
187
  - lib/ruby_fly/commands/set_pipeline.rb
160
188
  - lib/ruby_fly/commands/unpause_pipeline.rb
161
189
  - lib/ruby_fly/commands/version.rb
190
+ - lib/ruby_fly/rc.rb
162
191
  - lib/ruby_fly/version.rb
163
192
  homepage: https://github.com/tobyclemson/ruby_fly
164
193
  licenses:
@@ -175,9 +204,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
204
  version: '2.6'
176
205
  required_rubygems_version: !ruby/object:Gem::Requirement
177
206
  requirements:
178
- - - ">="
207
+ - - ">"
179
208
  - !ruby/object:Gem::Version
180
- version: '0'
209
+ version: 1.3.1
181
210
  requirements: []
182
211
  rubygems_version: 3.0.1
183
212
  signing_key: