battlecry 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,27 @@
1
+ #Battlecry - A simple abstraction for sydicating messages to OSX hosts via Growl
2
+
3
+ ##Installation
4
+
5
+ gem install ruby-growl
6
+ gem install battlecry -s http://gemcutter.org
7
+
8
+ ## Examples
9
+
10
+ battlecry = Battlecry.new [{
11
+ :host => "localhost"
12
+ },{
13
+ :host => "otherhost",
14
+ :password => "password"
15
+ }]
16
+
17
+ #shout a might shout, and all allies will know!
18
+ battlecry.shout "Victory is ours!"
19
+
20
+ #add another ally
21
+ battlecry.add_ally "hostname", "password"
22
+
23
+ #see the army size
24
+ battlecry.num_allies
25
+
26
+ ##Dependencies
27
+ - ruby-growl
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run All Specs"
5
+ Spec::Rake::SpecTask.new("spec") do |t|
6
+ t.spec_files = FileList["spec/**/*_spec.rb"]
7
+ end
data/battlecry.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'battlecry'
3
+ s.version = '0.1'
4
+ s.date = '2010-06-16'
5
+ s.summary = 'A simple abstraction for sydicating messages to OSX hosts via Growl'
6
+ s.email = 'dan.simpson@gmail.com'
7
+ s.homepage = 'http://github.com/dansimpson/battlecry'
8
+ s.description = 'A simple abstraction for sydicating messages to OSX hosts via Growl'
9
+ s.has_rdoc = true
10
+
11
+ s.authors = ['Dan Simpson']
12
+ s.add_dependency('ruby-growl', '>= 2.0')
13
+
14
+ s.files = [
15
+ 'README.markdown',
16
+ 'battlecry.gemspec',
17
+ 'Rakefile',
18
+ 'spec/helper.rb',
19
+ 'spec/battlecry_spec.rb',
20
+ 'lib/battlecry.rb'
21
+ ]
22
+ end
data/lib/battlecry.rb ADDED
@@ -0,0 +1,83 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require "rubygems"
4
+ require "ruby-growl"
5
+
6
+ ##
7
+ # Battlecry is a simply abstraction for sending growl messages
8
+ # to many hosts (allies)
9
+ #
10
+ # See http://growl.info/
11
+ #
12
+ # depends on the ruby-growl gem
13
+ # gem install ruby-growl
14
+ #
15
+ # Allies must have OSX installed and must listen for incoming
16
+ # notifcations to hear the cry.
17
+ # You can enable this by going to the Growl configuration panel
18
+ # under System Preferences. Go to the network tab and check the following boxes
19
+ # - Listen for incoming notifications
20
+ # - Allow remote application registration
21
+ #
22
+ # = Example
23
+ #
24
+ # battlecry = Battlecry.new [{
25
+ # :host => "localhost"
26
+ # },{
27
+ # :host => "myhost.com",
28
+ # :password => "test"
29
+ # }]
30
+ # battlecry.shout "We will defeat our enemies!"
31
+ class Battlecry
32
+
33
+ VERSION = 0.1
34
+
35
+ ##
36
+ # Creates a Battlecry, which registers notificaitons with one or
37
+ # more remote machines, known as allies
38
+ #
39
+ # +allies+ is an array of allies which will be affected by
40
+ # a battlecry. An ally is a hash object with a :host param (hostname),
41
+ # and an optional :password param
42
+ # eg: { :host => "localhost", :password => "password" }
43
+
44
+ def initialize allies
45
+ @allies = []
46
+ allies.each do |ally|
47
+ add_ally ally[:host], ally[:password]
48
+ end
49
+ end
50
+
51
+ ##
52
+ # Battlecrys for all allies in the army
53
+ #
54
+ # +message+ the content of the battlecry
55
+ #
56
+ # +title+ the title, or context of the battlecry
57
+ #
58
+ # +priority+ the intensity of the cry from -2 to 2
59
+ #
60
+ # +sticky+ makes the cry stick in the heads of allies
61
+ def shout message, title = "Battlecry", priority = 0, sticky = false
62
+ @allies.each do |ally|
63
+ ally.notify "battlecry", title, message, priority, sticky
64
+ end
65
+ end
66
+
67
+ ##
68
+ # Adds an ally to the army
69
+ #
70
+ # +host+ the hostname of the ally
71
+ #
72
+ # +title+ the password for the ally
73
+ def add_ally host, password = nil
74
+ @allies << Growl.new(host, "battlecry", ["battlecry"], nil, password)
75
+ end
76
+
77
+ ##
78
+ # The size of the army
79
+ def num_allies
80
+ @allies.size
81
+ end
82
+
83
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ describe Battlecry do
4
+
5
+ before do
6
+ @battlecry = Battlecry.new [{ :host => "localhost" }]
7
+ end
8
+
9
+ it "should have a version" do
10
+ Battlecry.const_defined?("VERSION").should == true
11
+ end
12
+
13
+ it "should take a list of allies" do
14
+ @battlecry.num_allies.should equal(1)
15
+ end
16
+
17
+ it "should shout" do
18
+ @battlecry.should respond_to(:shout)
19
+ end
20
+
21
+ it "should allow additional allies" do
22
+ @battlecry.should respond_to(:add_ally)
23
+ end
24
+
25
+ it "should increase the army size when adding an ally" do
26
+ @battlecry.add_ally "site.com"
27
+ @battlecry.num_allies.should equal(2)
28
+ end
29
+
30
+ it "should shout and show a growl" do
31
+ @battlecry.shout "Test"
32
+ end
33
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__) + "/../lib/")
2
+
3
+ require "battlecry"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: battlecry
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Dan Simpson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-16 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ruby-growl
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 0
32
+ version: "2.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: A simple abstraction for sydicating messages to OSX hosts via Growl
36
+ email: dan.simpson@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - README.markdown
45
+ - battlecry.gemspec
46
+ - Rakefile
47
+ - spec/helper.rb
48
+ - spec/battlecry_spec.rb
49
+ - lib/battlecry.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/dansimpson/battlecry
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: A simple abstraction for sydicating messages to OSX hosts via Growl
84
+ test_files: []
85
+