Class: GemMaintainer::Session
- Inherits:
-
Object
- Object
- GemMaintainer::Session
- Defined in:
- lib/gem_maintainer/session.rb
Overview
Persists session state to ~/.gem_maintainer_session.json so a run can be resumed if interrupted.
Constant Summary collapse
- SESSION_FILE =
File.join(Dir.home, ".gem_maintainer_session.json")
Instance Attribute Summary collapse
-
#approved ⇒ Object
readonly
Returns the value of attribute approved.
-
#candidates ⇒ Object
readonly
Returns the value of attribute candidates.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
-
#unchanged ⇒ Object
readonly
Returns the value of attribute unchanged.
Class Method Summary collapse
Instance Method Summary collapse
- #approve(gem) ⇒ Object
- #changelog_for(gem_name) ⇒ Object
- #clear ⇒ Object
-
#initialize(options) ⇒ Session
constructor
A new instance of Session.
- #record_unchanged(names) ⇒ Object
-
#remaining ⇒ Object
Gems not yet actioned.
- #restore(data) ⇒ Object
- #resuming? ⇒ Boolean
- #skip(gem) ⇒ Object
- #start(candidates) ⇒ Object
- #store_changelog(gem_name, url) ⇒ Object
Constructor Details
#initialize(options) ⇒ Session
Returns a new instance of Session.
28 29 30 31 32 33 34 35 36 |
# File 'lib/gem_maintainer/session.rb', line 28 def initialize() @options = @candidates = [] @approved = [] @skipped = [] @unchanged = [] @changelogs = {} @resuming = false end |
Instance Attribute Details
#approved ⇒ Object (readonly)
Returns the value of attribute approved.
11 12 13 |
# File 'lib/gem_maintainer/session.rb', line 11 def approved @approved end |
#candidates ⇒ Object (readonly)
Returns the value of attribute candidates.
11 12 13 |
# File 'lib/gem_maintainer/session.rb', line 11 def candidates @candidates end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/gem_maintainer/session.rb', line 11 def @options end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped.
11 12 13 |
# File 'lib/gem_maintainer/session.rb', line 11 def skipped @skipped end |
#unchanged ⇒ Object (readonly)
Returns the value of attribute unchanged.
11 12 13 |
# File 'lib/gem_maintainer/session.rb', line 11 def unchanged @unchanged end |
Class Method Details
.from_file(options) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/gem_maintainer/session.rb', line 21 def self.from_file() data = JSON.parse(File.read(SESSION_FILE), symbolize_names: true) session = new() session.restore(data) session end |
.load_or_new(options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gem_maintainer/session.rb', line 13 def self.load_or_new() if [:resume] && File.exist?(SESSION_FILE) from_file() else new() end end |
Instance Method Details
#approve(gem) ⇒ Object
61 62 63 64 |
# File 'lib/gem_maintainer/session.rb', line 61 def approve(gem) @approved << gem save end |
#changelog_for(gem_name) ⇒ Object
71 72 73 |
# File 'lib/gem_maintainer/session.rb', line 71 def changelog_for(gem_name) @changelogs[gem_name] end |
#clear ⇒ Object
84 85 86 |
# File 'lib/gem_maintainer/session.rb', line 84 def clear File.delete(SESSION_FILE) if File.exist?(SESSION_FILE) end |
#record_unchanged(names) ⇒ Object
75 76 77 |
# File 'lib/gem_maintainer/session.rb', line 75 def record_unchanged(names) @unchanged = names end |
#remaining ⇒ Object
Gems not yet actioned
56 57 58 59 |
# File 'lib/gem_maintainer/session.rb', line 56 def remaining actioned_names = (@approved + @skipped).map { |g| g[:name] } @candidates.reject { |g| actioned_names.include?(g[:name]) } end |
#restore(data) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/gem_maintainer/session.rb', line 43 def restore(data) @candidates = data[:candidates].map { |c| c.transform_keys(&:to_sym) } @approved = data[:approved].map { |c| c.transform_keys(&:to_sym) } @skipped = data[:skipped].map { |c| c.transform_keys(&:to_sym) } @changelogs = (data[:changelogs] || {}).transform_keys(&:to_s) @resuming = true end |
#resuming? ⇒ Boolean
51 52 53 |
# File 'lib/gem_maintainer/session.rb', line 51 def resuming? @resuming end |
#skip(gem) ⇒ Object
66 67 68 69 |
# File 'lib/gem_maintainer/session.rb', line 66 def skip(gem) @skipped << gem save end |
#start(candidates) ⇒ Object
38 39 40 41 |
# File 'lib/gem_maintainer/session.rb', line 38 def start(candidates) @candidates = candidates save end |
#store_changelog(gem_name, url) ⇒ Object
79 80 81 82 |
# File 'lib/gem_maintainer/session.rb', line 79 def store_changelog(gem_name, url) @changelogs[gem_name] = url save end |