sidekick 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.sidekick CHANGED
@@ -3,15 +3,11 @@
3
3
  # by doing. Proper tests are welcome.
4
4
 
5
5
  watch '**/*.rb' do |paths|
6
- sh 'echo files updated'
7
- end
8
-
9
- every(5) do
10
- log 'Five seconds passed!'
6
+ log 'files updated'
11
7
  end
12
8
 
13
9
  every(20) do
14
- notify 'Are you tired of being notified yet?'
10
+ notify sh('fortune')
15
11
  end
16
12
 
17
13
  # vim:ft=ruby
data/README.textile CHANGED
@@ -1,15 +1,13 @@
1
- h1. Sidekick [Draft]
1
+ h1. Sidekick
2
2
 
3
3
  Sidekick is a command line tool to automatically trigger certain tasks following certain events, as defined in a @.sidekick@ file in your project folder.
4
4
 
5
5
  You would typically run it in the background while coding, to automatize things like restarting development servers on file changes, recompiling assets, continously running tests or periodically running commands.
6
6
 
7
- It is very easy to set up and extend.
8
-
9
7
 
10
8
  h2. Basic usage
11
9
 
12
- Install with @gem install sidekick@ and invoke it using the @sidekick@ shell command in your project folder. You should have a @.sidekick@ file in the active directory. Here is a sample:
10
+ Install with @gem install sidekick@ and invoke it using the @sidekick@ shell command in your project folder. You should have a @.sidekick@ file in it. Here is a sample:
13
11
 
14
12
  <pre>
15
13
  <code lang='ruby'>
@@ -21,34 +19,32 @@ watch '**/*.rb' do |paths|
21
19
  notify 'Are you tired of being notified yet?'
22
20
  end
23
21
 
24
- # shows a new fortune every 10 seconds
25
- every(10) do
26
- sh 'fortune'
22
+ # keeps the developers mind agile
23
+ every(10) do
24
+ notify sh('fortune')
27
25
  end
28
26
 
29
27
  </code>
30
28
  </pre>
31
29
 
32
- The @watch@ and @every@ commands are are triggers, while @notify@, @sh@, and @restart_passenger@ are helper methods. The currently available triggers and helpers are:
30
+ The @watch@ and @every@ commands above are are triggers, while @notify@, @sh@, and @restart_passenger@ are helper methods.
33
31
 
34
- Triggers:
32
+ h3. Currently available triggers:
35
33
 
36
- |@watch@|run on file changes|
37
- |@every(duration)@|run every @duration@ of seconds|
34
+ |@watch(glob)@|run on file changes matching @glob@. Globs like Dir[]. |
35
+ |@every(duration)@|run every @duration@ seconds|
38
36
 
39
- Helpers:
37
+ h3. Currently available helpers:
40
38
 
41
39
  |@sh@|run shell command, showing output, like in rake|
42
40
  |@log@|log events to screen. cleaner than puts.|
43
41
  |@notify@|notify user via growl, libnotify etc|
44
42
  |@running?(platform)@|os can be one of @[:linux, :darwin, :other]@|
45
- |@load_gem?(name)@|tries to load gem, true if success. otherwise false. informs user that more functions are available when it is installed|
43
+ |@load_gem?(name)@|tries to load gem, true if success. otherwise false. informs user that more functions are available if they make it available|
46
44
  |@restart_passenger@|restart passenger based environments by touching tmp/restart.txt|
47
45
 
48
46
  h2. Writing extensions
49
47
 
50
- Sidekick is very easy to extend.
51
-
52
48
  h3. Writing new helpers
53
49
 
54
50
  To add more helpers, simply add methods to @Sidekick::Helpers@, like this:
@@ -63,7 +59,7 @@ To add more helpers, simply add methods to @Sidekick::Helpers@, like this:
63
59
  </code>
64
60
  </pre>
65
61
 
66
- When adding a group it is cleaner to use a separate module under @Sidekick::Helpers@, and then include it.
62
+ When adding a group of methods it may be cleaner to use a separate module under @Sidekick::Helpers@, and then include it.
67
63
 
68
64
 
69
65
  h3. Writing new triggers
@@ -82,7 +78,7 @@ end
82
78
  </code>
83
79
  </pre>
84
80
 
85
- This is the implementation of the @every@ function mentioned earlier. The @timeshare@ method is provided by Sidekick, and will call the supplied block with the specified duration in seconds. This is also useful for polling something without blocking other triggers.
81
+ This is the internal implementation of the @every@ function mentioned earlier. The @timeshare@ method is provided by Sidekick to all extensions, and will call the supplied block each @duration@ seconds. This is also useful for polling something without blocking or forking.
86
82
 
87
83
  Triggers can also be written as a class interface. Here is an example of the above, translated as a class:
88
84
 
@@ -105,18 +101,18 @@ class Sidekick::Triggers::Every
105
101
  end
106
102
  end
107
103
 
104
+ Sidekick::Triggers.register_class(:watch, Watch)
105
+
108
106
  </code>
109
107
  </pre>
110
108
 
111
- Here, the optional @poll@ method functions like the callback block in the previous example. The @poll_freq@ method is also optional, and determines the frequency in seconds with which to call @poll@.
112
-
113
- h3. When writing your own extensions
109
+ Here, the optional @poll@ method functions like the callback block in the previous example. The @poll_freq@ method is also optional, and determines the frequency in seconds with which to call @poll@. Finally, notice the last statement, which registers the class.
114
110
 
115
- You can keep your extensions in the @.sidekick@ file, or in a separate gem, or (better yet) ask me to merge them into the main repository.
111
+ h2. Final lines...
116
112
 
117
- h2. One more feature
113
+ The main code chunk is just under 100 lines including documentation, excluding the default triggers and helpers. Why not read it..?
118
114
 
119
- Fascinatingly, the main code chunk is just under 100 lines including documentation, excluding the default triggers and helpers. Why not read it..?
115
+ You can keep your extensions in the @.sidekick@ file itself, or package in a separate gem, or ask me to merge them into the main repository.
120
116
 
121
117
  I got a bit of inspiration from the somewhat similar project "Guard":http://github.com/guard/guard
122
118
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -57,9 +57,10 @@ module Sidekick::Helpers
57
57
 
58
58
  def sh(cmd)
59
59
  log cmd
60
- puts `#{cmd}`
60
+ puts result = `#{cmd}`
61
+ result
61
62
  end
62
-
63
+
63
64
 
64
65
 
65
66
  def restart_passenger
@@ -3,14 +3,20 @@
3
3
  module Sidekick::Triggers::Watch
4
4
 
5
5
  def self.new(*args)
6
- case ::Sidekick::Helpers.platform
7
- when :linux then Polling
8
- when :darwin then Polling
9
- else Polling
10
- end.new(*args)
6
+
7
+ name, adapter_class = {
8
+ :linux => [nil, Polling], # Ready to implement fs-event
9
+ :darwin => [nil, Polling], # and libnotify. Polling seems
10
+ :other => [nil, Polling] # to work perfectly though.
11
+ }[::Sidekick::Helpers.platform]
12
+
13
+ unless name.nil?
14
+ adapter_class = Polling unless Sidekick::Helpers.load_gem?(name)
15
+ end
16
+ adapter_class.new(*args)
11
17
  end
12
18
 
13
- class Polling
19
+ class Polling # todo: check for deletion
14
20
 
15
21
  def initialize(callback, glob, ignore_first=false)
16
22
  ::Sidekick::Triggers.log "polling #{glob} for file changes.."
@@ -46,8 +52,4 @@ module Sidekick::Triggers::Watch
46
52
  end
47
53
  end
48
54
 
49
- # TODO inotify and mac support
50
-
51
-
52
-
53
55
  end
data/sidekick.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sidekick}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jostein Berre Eliassen,"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jostein Berre Eliassen,