Class: GitAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/git_agent.rb,
lib/git_agent/version.rb,
lib/git_agent/notification.rb

Defined Under Namespace

Classes: Notification

Constant Summary collapse

URLS =
{
  github: 'github.com',
  bitbucket: 'bitbucket.org'
}
VERSION =
'0.0.2'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ GitAgent

Returns a new instance of GitAgent.



19
20
21
22
# File 'lib/git_agent.rb', line 19

def initialize(args = {})
  @homepage = args[:homepage]
  @url, @username, @project = resolve_arguments(args)
end

Class Attribute Details

.data_directoryObject

Returns the value of attribute data_directory.



9
10
11
# File 'lib/git_agent.rb', line 9

def data_directory
  @data_directory
end

Instance Attribute Details

#homepageObject (readonly)

Returns the value of attribute homepage.



12
13
14
# File 'lib/git_agent.rb', line 12

def homepage
  @homepage
end

#projectObject (readonly)

Returns the value of attribute project.



12
13
14
# File 'lib/git_agent.rb', line 12

def project
  @project
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/git_agent.rb', line 12

def url
  @url
end

#usernameObject (readonly)

Returns the value of attribute username.



12
13
14
# File 'lib/git_agent.rb', line 12

def username
  @username
end

Instance Method Details

#diffObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/git_agent.rb', line 24

def diff
  old_hash, new_hash = read_from_record, ls_remote
  old_keys, new_keys = old_hash.keys, new_hash.keys

  same_keys = new_keys & old_keys
  result = {
    added: new_keys - same_keys,
    deleted: old_keys - same_keys,
    updated: []
  }

  same_keys.inject(result[:updated]) do |memo, key|
    memo << key if old_hash[key] != new_hash[key]
    memo
  end

  record(new_hash)

  result
end

#notify_if_different!Object



45
46
47
48
49
50
51
52
# File 'lib/git_agent.rb', line 45

def notify_if_different!
  result = diff

  unless result.values.flatten.empty?
    notification = GitAgent::Notification.new(project, homepage, result)
    notification.send!
  end
end