piggy 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+
2
+ ## TODO
3
+ * Autotest hook
4
+ * Kermit hook
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.1.0
@@ -10,16 +10,16 @@ Feature: Use git hooks
10
10
  Successfully installed git hook.
11
11
  Piggy is now monitoring the git commits made in this project.
12
12
  """
13
- And the file ".git/hooks/post-commit" should contain "Piggy"
13
+ And the file ".git/hooks/post-commit" should contain "piggy"
14
14
  And the file ".git/hooks/post-commit" should be executable
15
-
16
- # @wip
17
- # Scenario: A git commit should trigger a Piggy event
18
- # Given the git hook is installed
19
- # And an empty file named "foo.txt"
20
- # When I run "git add foo.txt"
21
- # And I run "git commit -m 'First commit'"
22
- # Then an event should be triggered with title "First commit"
15
+
16
+ Scenario: A git commit should publish a Piggy event
17
+ Given the git hook is installed
18
+ And an empty file named "foo.txt"
19
+ When I run "git add foo.txt"
20
+ And I run "git commit -m 'First commit'"
21
+ And I run "piggy history"
22
+ Then the output should contain exactly "First commit\n"
23
23
 
24
24
 
25
25
 
@@ -0,0 +1,19 @@
1
+ Feature: Event and History
2
+ In order to test publishers
3
+ As a Piggy developer
4
+ I want to publish events, and discover events that Piggy has reported
5
+
6
+ Scenario: No history initially
7
+ When I run "piggy history"
8
+ Then the output should be empty
9
+
10
+ Scenario: A published event is shown in the history
11
+ When I run "piggy event 'Hello world!'"
12
+ And I run "piggy history"
13
+ Then the output should contain exactly "Hello world!\n"
14
+
15
+ Scenario: Events are ordered most recent first in the history
16
+ When I run "piggy event first"
17
+ When I run "piggy event second"
18
+ And I run "piggy history"
19
+ Then the output should contain exactly "second\nfirst\n"
@@ -1,4 +1,4 @@
1
- Feature: Get help
1
+ Feature: Help
2
2
  In order to find out how to use Piggy
3
3
  As a programmer
4
4
  I want to view help
@@ -1,4 +1,5 @@
1
1
  Given /^the git hook is installed$/ do
2
- When "I run \"git init\""
2
+ When "I run \"rake install\""
3
+ And "I run \"git init\""
3
4
  And "I run \"piggy install\""
4
5
  end
@@ -0,0 +1,3 @@
1
+ Then /^the output should be empty$/ do
2
+ Then "the output should contain exactly \"\""
3
+ end
@@ -0,0 +1,8 @@
1
+ Given /^a subscriber at "([^"]*)" that writes to "([^"]*)"$/ do |sub_path, out_path|
2
+ Given "an executable file named \"#{sub_path}\" with:", subscriber(out_path)
3
+ end
4
+
5
+ def subscriber(out_path)
6
+ "#!/usr/bin/env ruby\n" +
7
+ "File.open('#{out_path}', 'w') {|f| f.write(ARGV.first) }"
8
+ end
@@ -11,13 +11,18 @@ Piggy is now sending events to 'writer.rb'.
11
11
  """
12
12
 
13
13
  Scenario: Receive events from Piggy
14
- Given an executable file named "writer.rb" with:
15
- """
16
- #!/usr/bin/env ruby
14
+ Given a subscriber at "sub.rb" that writes to "output.txt"
15
+ And I run "piggy subscribe sub.rb"
16
+ And I run "piggy event 'Hello world!'"
17
+ Then the output should be empty
18
+ And the file "output.txt" should contain "Hello world!"
17
19
 
18
- File.open('output.txt', 'w') {|f| f.write(ARGV.first) }
19
- """
20
- And I run "piggy subscribe writer.rb"
21
- And an event is triggered with title "Hello world!"
22
- Then the file "output.txt" should contain "Hello world!"
23
-
20
+ Scenario: All subscribers should receive the same event
21
+ Given a subscriber at "sub1.rb" that writes to "one.txt"
22
+ And a subscriber at "sub2.rb" that writes to "two.txt"
23
+ And I run "piggy subscribe sub1.rb"
24
+ And I run "piggy subscribe sub2.rb"
25
+ And I run "piggy event 'Hello world!'"
26
+ Then the output should be empty
27
+ And the file "one.txt" should contain "Hello world!"
28
+ And the file "two.txt" should contain "Hello world!"
data/lib/piggy/cli.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'thor'
2
2
 
3
3
  require 'piggy/version'
4
+ require 'piggy/event'
5
+ require 'piggy/subscribers'
4
6
 
5
7
  module Piggy
6
8
  class CLI < Thor
@@ -26,8 +28,18 @@ module Piggy
26
28
 
27
29
  desc "subscribe PROGRAM", "Add a program that will receive Piggy events"
28
30
  def subscribe(subscriber)
29
- create_file ".piggy/subscribers", subscriber
31
+ Subscribers.add subscriber
30
32
  puts "Piggy is now sending events to '#{subscriber}'."
31
33
  end
34
+
35
+ desc "event", "Publish an event"
36
+ def event(title)
37
+ Event.create title
38
+ end
39
+
40
+ desc "history", "List all published events"
41
+ def history
42
+ puts Event.all if Event.any?
43
+ end
32
44
  end
33
45
  end
data/lib/piggy/event.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'active_model'
2
2
 
3
+ require 'piggy/subscribers'
4
+ require 'piggy/file_store'
5
+
3
6
  module Piggy
4
7
  class Event
5
8
  include ActiveModel::Serializers::Xml
@@ -7,12 +10,32 @@ module Piggy
7
10
 
8
11
  attr_accessor :title
9
12
 
10
- def initialize(title)
11
- @title = title
13
+ def self.create(title)
14
+ event = Event.new(title)
15
+ store.save(title)
16
+ Subscribers.notify(event)
17
+ event
18
+ end
19
+
20
+ def self.all
21
+ store.all.reverse.join("\n")
22
+ end
23
+
24
+ def self.any?
25
+ store.any?
12
26
  end
13
27
 
14
28
  def attributes
15
29
  @attributes ||= {'title' => 'nil'}
16
30
  end
31
+
32
+ private
33
+ def initialize(title)
34
+ @title = title
35
+ end
36
+
37
+ def self.store
38
+ Piggy::FileStore.new('events')
39
+ end
17
40
  end
18
41
  end
@@ -0,0 +1,41 @@
1
+ module Piggy
2
+ class FileStore
3
+ def initialize(store)
4
+ @store = store
5
+ end
6
+
7
+ def clear
8
+ delete_store if store_exists?
9
+ end
10
+
11
+ def save(text)
12
+ create_store unless store_exists?
13
+ File.open(store, 'a') {|f| f.write(text + "\n") }
14
+ end
15
+
16
+ def all
17
+ any? ? IO.readlines(store).map(&:chomp) : []
18
+ end
19
+
20
+ def any?
21
+ store_exists?
22
+ end
23
+
24
+ private
25
+ def store
26
+ ".piggy/#{@store}"
27
+ end
28
+
29
+ def create_store
30
+ Dir.mkdir('.piggy') unless Dir.exists?('.piggy')
31
+ end
32
+
33
+ def delete_store
34
+ File.delete(store)
35
+ end
36
+
37
+ def store_exists?
38
+ File.exists? store
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ require 'piggy/file_store'
2
+
3
+ module Piggy
4
+ class Subscribers
5
+ def self.notify(event)
6
+ store.all.each do |subscriber|
7
+ `./#{subscriber} "#{event.title}"`
8
+ end
9
+ end
10
+
11
+ def self.add(subscriber)
12
+ store.save(subscriber)
13
+ end
14
+
15
+ private
16
+ def self.store
17
+ FileStore.new('subscribers')
18
+ end
19
+ end
20
+ end
data/piggy.gemspec CHANGED
@@ -5,39 +5,43 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{piggy}
8
- s.version = "0.0.6"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Louis Rose"]
12
- s.date = %q{2010-09-07}
12
+ s.date = %q{2010-09-09}
13
13
  s.default_executable = %q{piggy}
14
14
  s.description = %q{Record and analyse coding sessions}
15
15
  s.email = %q{louismrose@gmail.com}
16
16
  s.executables = ["piggy"]
17
17
  s.extra_rdoc_files = [
18
- "README"
18
+ "README.md"
19
19
  ]
20
20
  s.files = [
21
21
  ".gitignore",
22
22
  "Gemfile",
23
23
  "Gemfile.lock",
24
- "README",
24
+ "README.md",
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "bin/piggy",
28
- "features/get_help.feature",
29
- "features/git_hook.feature",
30
- "features/step_definitions/event_steps.rb",
28
+ "features/bundled_hooks/git_hook.feature",
29
+ "features/event_and_history.feature",
30
+ "features/help.feature",
31
31
  "features/step_definitions/file_system_steps.rb",
32
32
  "features/step_definitions/git_steps.rb",
33
+ "features/step_definitions/output_steps.rb",
34
+ "features/step_definitions/subscriber_steps.rb",
33
35
  "features/subscription.feature",
34
36
  "features/support/env.rb",
35
37
  "lib/piggy/cli.rb",
36
38
  "lib/piggy/event.rb",
37
- "lib/piggy/events.rb",
39
+ "lib/piggy/file_store.rb",
40
+ "lib/piggy/subscribers.rb",
38
41
  "lib/piggy/version.rb",
39
42
  "piggy.gemspec",
40
- "spec/event.spec.rb",
43
+ "spec/piggy/event.spec.rb",
44
+ "spec/piggy/file_store.spec.rb",
41
45
  "spec/spec_helper.rb",
42
46
  "templates/git_hook"
43
47
  ]
@@ -46,7 +50,8 @@ Gem::Specification.new do |s|
46
50
  s.rubygems_version = %q{1.3.7}
47
51
  s.summary = %q{Record and analyse coding sessions}
48
52
  s.test_files = [
49
- "spec/event.spec.rb",
53
+ "spec/piggy/event.spec.rb",
54
+ "spec/piggy/file_store.spec.rb",
50
55
  "spec/spec_helper.rb"
51
56
  ]
52
57
 
File without changes
@@ -0,0 +1,52 @@
1
+ require 'piggy/file_store'
2
+
3
+ describe "file-based persistency" do
4
+ def store
5
+ Piggy::FileStore.new('.test')
6
+ end
7
+
8
+ after(:all) do
9
+ store.clear
10
+ end
11
+
12
+ context "when empty" do
13
+ it "should not have any entries" do
14
+ store.any?.should be_false
15
+ end
16
+
17
+ it "should return 0 entries when asked for all" do
18
+ store.all.should be_empty
19
+ end
20
+ end
21
+
22
+ context "after saving one entry" do
23
+ before(:all) do
24
+ store.clear
25
+ store.save('foo')
26
+ end
27
+
28
+ it "should have some entries" do
29
+ store.any?.should be_true
30
+ end
31
+
32
+ it "should return a singleton as the list of all entries" do
33
+ store.all.should == %w{foo}
34
+ end
35
+ end
36
+
37
+ context "after saving two entries" do
38
+ before(:all) do
39
+ store.clear
40
+ store.save('foo')
41
+ store.save('bar')
42
+ end
43
+
44
+ it "should have some entries" do
45
+ store.any?.should be_true
46
+ end
47
+
48
+ it "should return the list of all entries" do
49
+ store.all.should == %w{foo bar}
50
+ end
51
+ end
52
+ end
data/templates/git_hook CHANGED
@@ -1 +1,2 @@
1
- Piggy
1
+ #!/bin/sh
2
+ piggy event "`git log -n 1 --pretty=format:%s`"
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 6
9
- version: 0.0.6
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Louis Rose
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-07 00:00:00 +01:00
17
+ date: 2010-09-09 00:00:00 +01:00
18
18
  default_executable: piggy
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -109,28 +109,32 @@ executables:
109
109
  extensions: []
110
110
 
111
111
  extra_rdoc_files:
112
- - README
112
+ - README.md
113
113
  files:
114
114
  - .gitignore
115
115
  - Gemfile
116
116
  - Gemfile.lock
117
- - README
117
+ - README.md
118
118
  - Rakefile
119
119
  - VERSION
120
120
  - bin/piggy
121
- - features/get_help.feature
122
- - features/git_hook.feature
123
- - features/step_definitions/event_steps.rb
121
+ - features/bundled_hooks/git_hook.feature
122
+ - features/event_and_history.feature
123
+ - features/help.feature
124
124
  - features/step_definitions/file_system_steps.rb
125
125
  - features/step_definitions/git_steps.rb
126
+ - features/step_definitions/output_steps.rb
127
+ - features/step_definitions/subscriber_steps.rb
126
128
  - features/subscription.feature
127
129
  - features/support/env.rb
128
130
  - lib/piggy/cli.rb
129
131
  - lib/piggy/event.rb
130
- - lib/piggy/events.rb
132
+ - lib/piggy/file_store.rb
133
+ - lib/piggy/subscribers.rb
131
134
  - lib/piggy/version.rb
132
135
  - piggy.gemspec
133
- - spec/event.spec.rb
136
+ - spec/piggy/event.spec.rb
137
+ - spec/piggy/file_store.spec.rb
134
138
  - spec/spec_helper.rb
135
139
  - templates/git_hook
136
140
  has_rdoc: true
@@ -166,5 +170,6 @@ signing_key:
166
170
  specification_version: 3
167
171
  summary: Record and analyse coding sessions
168
172
  test_files:
169
- - spec/event.spec.rb
173
+ - spec/piggy/event.spec.rb
174
+ - spec/piggy/file_store.spec.rb
170
175
  - spec/spec_helper.rb
data/README DELETED
File without changes
@@ -1,9 +0,0 @@
1
- require 'piggy/events'
2
-
3
- When /^an event is triggered with title "([^"]*)"$/ do |title|
4
- Piggy::Events.trigger title
5
- end
6
-
7
- Then /^an event should be triggered with title "([^"]*)"$/ do |title|
8
- Piggy::Events.last.title.should == title
9
- end
data/lib/piggy/events.rb DELETED
@@ -1,11 +0,0 @@
1
- require 'piggy/event'
2
-
3
- module Piggy
4
- class Events
5
- def self.trigger(title)
6
- xml = Event.new(title).to_xml
7
- subscriber = IO.readlines("tmp/aruba/.piggy/subscribers").first
8
- `cd tmp/aruba; ./#{subscriber} "#{xml}"`
9
- end
10
- end
11
- end