Class: Sink

Inherits:
Object
  • Object
show all
Defined in:
lib/sink.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSink

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

#dirObject

Returns the value of attribute dir.



8
9
10
# File 'lib/sink.rb', line 8

def dir
  @dir
end

#gitObject

Returns the value of attribute git.



8
9
10
# File 'lib/sink.rb', line 8

def git
  @git
end

#githubObject

Returns the value of attribute github.



8
9
10
# File 'lib/sink.rb', line 8

def github
  @github
end

#nwoObject

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

Parameters:

  • value

    the value to set the attribute status to.



8
9
10
# File 'lib/sink.rb', line 8

def status=(value)
  @status = value
end

Instance Method Details

#watchObject



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(commit_message)
      @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