Class: Sink
- Inherits:
-
Object
- Object
- Sink
- Defined in:
- lib/sink.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#git ⇒ Object
Returns the value of attribute git.
-
#github ⇒ Object
Returns the value of attribute github.
-
#nwo ⇒ Object
Returns the value of attribute nwo.
-
#status ⇒ Object
writeonly
Sets the attribute status.
Instance Method Summary collapse
-
#initialize ⇒ Sink
constructor
A new instance of Sink.
- #watch ⇒ Object
Constructor Details
#initialize ⇒ Sink
Returns a new instance of Sink.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sink.rb', line 10 def initialize Dotenv.load "~/.sinkconfig" puts "Configuration loaded: ✔" @dir = Dir.pwd @git = Git.open(@dir) @github = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"]) if dir_is_syncable? @nwo = @git.remotes.select { |r| r.name == 'origin' } .first.url .gsub(/https:\/\/github.com\//, '') .gsub(/\.git/, '') puts "GitHub remote detected: ✔" else puts "Not a git repo, sorry! Exiting…" exit end watch end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
8 9 10 |
# File 'lib/sink.rb', line 8 def dir @dir end |
#git ⇒ Object
Returns the value of attribute git.
8 9 10 |
# File 'lib/sink.rb', line 8 def git @git end |
#github ⇒ Object
Returns the value of attribute github.
8 9 10 |
# File 'lib/sink.rb', line 8 def github @github end |
#nwo ⇒ Object
Returns the value of attribute nwo.
8 9 10 |
# File 'lib/sink.rb', line 8 def nwo @nwo end |
#status=(value) ⇒ Object
Sets the attribute status
8 9 10 |
# File 'lib/sink.rb', line 8 def status=(value) @status = value end |
Instance Method Details
#watch ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sink.rb', line 32 def watch puts "Watching for changes…" while true if unstaged_changes? @git.add(all: true) @git.commit() @git.push('origin') puts "Latest changes pushed!" end if remote_head_sha != local_head_sha puts "Remote changes detected. Syncing…" @git.pull('origin') puts "Done." end end end |