Class: SVNCampfireNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/svn_campfire_notifier.rb,
lib/svn_campfire_notifier/message.rb,
lib/svn_campfire_notifier/project.rb,
lib/svn_campfire_notifier/google_image.rb

Defined Under Namespace

Classes: ConfigurationError, GoogleImage, Message, Project

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_mode, repository_path, revision) ⇒ SVNCampfireNotifier

Returns a new instance of SVNCampfireNotifier.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/svn_campfire_notifier.rb', line 18

def initialize(test_mode, repository_path, revision)
  @test_mode = test_mode
  @project   = Project.new(repository_path, revision)
  
  @settings  = YAML.load_file(configuration_filename)
  @room      = @settings['room']
  Broach.settings = {
    'account' => @settings['account'],
    'token'   => @settings['token'],
    'use_ssl' => @settings['use_ssl']
  }
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



16
17
18
# File 'lib/svn_campfire_notifier.rb', line 16

def project
  @project
end

Class Method Details

.run(options, args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/svn_campfire_notifier.rb', line 66

def self.run(options, args)
  if args.length == 2
    new(
      options.keys.include?('t') || options.keys.include?('test'),
      *args
    ).run
  else
    usage
  end
end

.usageObject



58
59
60
61
62
63
64
# File 'lib/svn_campfire_notifier.rb', line 58

def self.usage
  puts "Usage: #{File.basename($0)} <repository> <revision>"
  puts ""
  puts "Options:"
  puts "  -v, --verbose: Print informative messages"
  puts "  -t, --test:    Don't send to Campfire, just print what you would send"
end

Instance Method Details

#configuration_filenameObject



31
32
33
34
35
36
37
38
# File 'lib/svn_campfire_notifier.rb', line 31

def configuration_filename
  begin
    filename = File.expand_path('~/.svn_campfire_notifier.yml')
    return filename if File.exist?(filename)
  rescue ArgumentError
  end
  '/etc/svn_campfire_notifier.yml'
end

#runObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/svn_campfire_notifier.rb', line 44

def run
  if test_mode?
    Message.new(project).parts.each do |part|
      puts part.first
    end
  elsif room = Broach::Room.find_by_name(@room)
    Message.new(project).parts.each do |part|
      room.speak(*part)
    end
  else
    raise ConfigurationError, "Can't find a room with the name `#{@room}'"
  end
end

#test_mode?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/svn_campfire_notifier.rb', line 40

def test_mode?
  @test_mode
end