eac_launcher 0.2.2 → 0.3.0

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
  SHA1:
3
- metadata.gz: be146005c131fcd24f8226cac90684e1e6580e66
4
- data.tar.gz: 3699b4549409d7a83879078e8938e455d0767f16
3
+ metadata.gz: 7c5a7b375361961ba04d494e5951f67f9a3fef5b
4
+ data.tar.gz: 8346f75d6b450beaca58be9b77a8468fff5b115b
5
5
  SHA512:
6
- metadata.gz: 48db93c8e6905615edf42facb4e248964180355dc709e568b03954e23f3abea7d210b6f50102ac40156a54eb93da2aeee9bea6f5071de91c123833d30f5d2b3e
7
- data.tar.gz: 430bb4b45fe6ff30a9cd6e919fcdb5467343c915f3bfc42f5779939c9c4843d0da08c85e91ac4946c5bc656986960715d95abf91cec28bf2455ecf3aede19835
6
+ metadata.gz: eb45c7cffc1795bf357ed5eaafa1110d95ca070e5ea7b816881d75b44af0b77337a05125c29520277fcb6cc37e5dad27624ee8cfa7e7bc5a09a75182bea5f988
7
+ data.tar.gz: 2b0e5822b3addeee9bbf09619569caba0f5def8bc2843a4ef8ab33c3b5732aa05cd2591ee1c7e2ed23dde7457741a96e84cc5e572e414b5c3e2d5dbf0f0f4a5a
@@ -6,6 +6,8 @@ module EacLauncher
6
6
  include ::Eac::SimpleCache
7
7
  include ::EacRubyUtils::Console::Speaker
8
8
 
9
+ CHECKERS = %w[publish_remote_no_exist remote_equal remote_following local_following].freeze
10
+
9
11
  def initialize(instance)
10
12
  @instance = instance
11
13
  end
@@ -13,27 +15,49 @@ module EacLauncher
13
15
  protected
14
16
 
15
17
  def internal_check
16
- if publish_remote_no_exist?
17
- ::EacLauncher::Publish::CheckResult.blocked('Remote does not exist')
18
- elsif remote_equal_or_following?
19
- ::EacLauncher::Publish::CheckResult.updated('Remote equal or following')
20
- elsif local_following?
21
- ::EacLauncher::Publish::CheckResult.pending('Local following')
22
- else
23
- divergent_result
24
- end
18
+ CHECKERS.each { |checker| return send("#{checker}_check_result") if send("#{checker}?") }
19
+ divergent_result_check_result
25
20
  end
26
21
 
27
22
  private
28
23
 
29
- def divergent_result
24
+ def publish_remote_no_exist?
25
+ !sgit.remote_exist?(::EacLauncher::Git::WarpBase::TARGET_REMOTE)
26
+ end
27
+
28
+ def publish_remote_no_exist_check_result
29
+ ::EacLauncher::Publish::CheckResult.blocked('Remote does not exist')
30
+ end
31
+
32
+ def remote_equal?
33
+ remote_sha.present? && remote_sha == local_sha
34
+ end
35
+
36
+ def remote_equal_check_result
37
+ ::EacLauncher::Publish::CheckResult.updated('Remote equal')
38
+ end
39
+
40
+ def remote_following?
41
+ remote_sha.present? && sgit.descendant?(remote_sha, local_sha)
42
+ end
43
+
44
+ def remote_following_check_result
45
+ ::EacLauncher::Publish::CheckResult.outdated('Remote following')
46
+ end
47
+
48
+ def divergent_result_check_result
30
49
  ::EacLauncher::Publish::CheckResult.blocked(
31
50
  "Divergent (L: #{local_sha}, R: #{remote_sha})"
32
51
  )
33
52
  end
34
53
 
35
- def publish_remote_no_exist?
36
- !sgit.remote_exist?(::EacLauncher::Git::WarpBase::TARGET_REMOTE)
54
+ def local_following?
55
+ return true if remote_sha.blank?
56
+ sgit.descendant?(local_sha, remote_sha)
57
+ end
58
+
59
+ def local_following_check_result
60
+ ::EacLauncher::Publish::CheckResult.pending('Local following')
37
61
  end
38
62
 
39
63
  def sgit_uncached
@@ -47,16 +71,6 @@ module EacLauncher
47
71
  info 'Pushed!'
48
72
  end
49
73
 
50
- def remote_equal_or_following?
51
- return false if remote_sha.blank?
52
- remote_sha == local_sha || sgit.descendant?(remote_sha, local_sha)
53
- end
54
-
55
- def local_following?
56
- return true if remote_sha.blank?
57
- sgit.descendant?(local_sha, remote_sha)
58
- end
59
-
60
74
  def local_sha
61
75
  sgit.git.object('HEAD').sha
62
76
  end
@@ -1,41 +1,55 @@
1
+ require 'eac/listable'
2
+
1
3
  module EacLauncher
2
4
  module Publish
3
5
  class CheckResult
4
- STATUS_UPDATED = 1
5
- STATUS_PENDING = 2
6
- STATUS_BLOCKED = 3
6
+ include ::Eac::Listable
7
+
8
+ lists.add_string :status, :updated, :pending, :blocked, :outdated
7
9
 
8
- STATUSES = [STATUS_UPDATED, STATUS_PENDING, STATUS_BLOCKED].freeze
10
+ lists.status.values.each do |status|
11
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
12
+ def self.#{status}(message)
13
+ new('#{status}', message)
14
+ end
15
+ RUBY_EVAL
16
+ end
9
17
 
10
18
  class << self
11
- def updated(message)
12
- new(STATUS_UPDATED, message)
19
+ def updated_color
20
+ 'green'
21
+ end
22
+
23
+ def pending_color
24
+ 'yellow'
13
25
  end
14
26
 
15
- def pending(message)
16
- new(STATUS_PENDING, message)
27
+ def blocked_color
28
+ 'red'
17
29
  end
18
30
 
19
- def blocked(message)
20
- new(STATUS_BLOCKED, message)
31
+ def outdated_color
32
+ 'light_blue'
21
33
  end
22
34
  end
23
35
 
24
36
  attr_reader :status, :message
25
37
 
26
38
  def initialize(status, message)
27
- raise "Status \"#{status}\" not in #{STATUSES}" unless STATUSES.include?(status)
39
+ raise "Status \"#{status}\" not in #{self.class.lists.status.values}" unless
40
+ self.class.lists.status.values.include?(status)
28
41
  @status = status
29
42
  @message = message
30
43
  end
31
44
 
32
45
  def to_s
33
- case status
34
- when STATUS_UPDATED then message.light_white.on_green
35
- when STATUS_PENDING then message.light_white.on_yellow
36
- when STATUS_BLOCKED then message.light_white.on_red
37
- else raise "Unknown status: \"#{status}\""
38
- end
46
+ message.light_white.send("on_#{background_color}")
47
+ end
48
+
49
+ private
50
+
51
+ def background_color
52
+ self.class.send("#{status}_color")
39
53
  end
40
54
  end
41
55
  end
@@ -12,19 +12,47 @@ module EacLauncher
12
12
  protected
13
13
 
14
14
  def internal_check
15
- if new_and_unpublishing_new?
16
- ::EacLauncher::Publish::CheckResult.blocked(
17
- "#{gem_spec.full_name} does not exist in RubyGems"
18
- )
19
- elsif version_already_pushed?
20
- ::EacLauncher::Publish::CheckResult.updated("#{gem_spec.full_name} already pushed")
15
+ gem_published? ? internal_check_gem_published : internal_check_gem_unpublished
16
+ end
17
+
18
+ private
19
+
20
+ def internal_check_gem_published
21
+ if version_published?
22
+ outdated_version? ? outdated_version_check_result : version_published_check_result
21
23
  else
22
- ::EacLauncher::Publish::CheckResult.pending("#{gem_spec.full_name} not found " \
23
- 'in RubyGems')
24
+ version_unpublished_check_result
24
25
  end
25
26
  end
26
27
 
27
- private
28
+ def internal_check_gem_unpublished
29
+ if new_gem_allowed?
30
+ version_unpublished_check_result
31
+ else
32
+ new_gem_disallowed_check_result
33
+ end
34
+ end
35
+
36
+ def new_gem_disallowed_check_result
37
+ ::EacLauncher::Publish::CheckResult.blocked(
38
+ "#{gem_spec.full_name} does not exist in RubyGems"
39
+ )
40
+ end
41
+
42
+ def version_published_check_result
43
+ ::EacLauncher::Publish::CheckResult.updated("#{gem_spec.full_name} already pushed")
44
+ end
45
+
46
+ def outdated_version_check_result
47
+ ::EacLauncher::Publish::CheckResult.outdated(
48
+ "#{gem_spec.full_name} is outdated (Max: #{gem_version_max})"
49
+ )
50
+ end
51
+
52
+ def version_unpublished_check_result
53
+ ::EacLauncher::Publish::CheckResult.pending("#{gem_spec.full_name} not found " \
54
+ 'in RubyGems')
55
+ end
28
56
 
29
57
  def source_uncached
30
58
  @instance.warped
@@ -45,18 +73,22 @@ module EacLauncher
45
73
  gem_build.close
46
74
  end
47
75
 
48
- def new_and_unpublishing_new?
49
- !gem_exist_in_rubygems? && !::EacLauncher::Context.current.publish_options[:new]
76
+ def new_gem_allowed?
77
+ ::EacLauncher::Context.current.publish_options[:new]
50
78
  end
51
79
 
52
- def gem_exist_in_rubygems?
80
+ def gem_published?
53
81
  gem_versions.any?
54
82
  end
55
83
 
56
- def version_already_pushed?
84
+ def version_published?
57
85
  gem_versions.any? { |v| v['number'] == gem_spec.version }
58
86
  end
59
87
 
88
+ def outdated_version?
89
+ gem_version_max.present? && ::Gem::Version.new(gem_spec.version) < gem_version_max
90
+ end
91
+
60
92
  def gem_versions_uncached
61
93
  http = Curl.get("https://rubygems.org/api/v1/versions/#{gem_spec.name}.json")
62
94
  return JSON.parse!(http.body_str) if /\A2/ =~ http.status
@@ -64,6 +96,10 @@ module EacLauncher
64
96
  raise "#{http} code error: #{http.status}"
65
97
  end
66
98
 
99
+ def gem_version_max_uncached
100
+ gem_versions.map { |v| ::Gem::Version.new(v['number']) }.max
101
+ end
102
+
67
103
  def push_gem
68
104
  info("Pushing gem #{gem_spec}...")
69
105
  command = ['gem', 'push', gem_build.output_file]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacLauncher
4
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.3.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-16 00:00:00.000000000 Z
11
+ date: 2018-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport