mm 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -0,0 +1,9 @@
1
+ require 'rake'
2
+
3
+ require 'rubygems/package_task'
4
+
5
+ spec = Gem::Specification.load "mm.gemspec"
6
+ Gem::PackageTask.new(spec) do |pkg|
7
+ pkg.need_zip = true
8
+ pkg.need_tar = true
9
+ end
data/lib/turbine.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
 
3
+ module Turbine
4
+ PRECISION = 2 # decimal places for rounding
5
+ end
6
+
3
7
  require "turbine/timer"
4
8
  require "turbine/queue"
5
9
  require "turbine/commands/init"
@@ -17,6 +17,13 @@ module Turbine
17
17
  end
18
18
  end
19
19
 
20
+ def global_config_dir
21
+ path = File.expand_path("~/.turbine")
22
+ if File.exist?(path)
23
+ path
24
+ end
25
+ end
26
+
20
27
  def extensions
21
28
  @extensions ||= []
22
29
  end
@@ -7,12 +7,16 @@ module Turbine
7
7
  init_and_exit(*argv) if argv[0] == "init"
8
8
 
9
9
  unless self.class.config_dir
10
- prompt.say "Cannot find config file. Did you forget to run turbine init?"
10
+ prompt.say "Cannot find config file. Did you forget to run mm init?"
11
11
  return
12
12
  end
13
13
 
14
14
  require "#{self.class.config_dir}/config"
15
15
 
16
+ if self.class.global_config_dir
17
+ Dir["#{self.class.global_config_dir}/commands/*.rb"].each { |f| load f }
18
+ end
19
+
16
20
  self.class.extensions.each do |extension|
17
21
  extend(extension)
18
22
  end
@@ -20,13 +24,13 @@ module Turbine
20
24
  setup
21
25
  parse_options(*argv)
22
26
 
23
- if respond_to?(command)
27
+ if command && respond_to?(command)
24
28
  send(command)
25
29
  else
26
30
  prompt.say("Unknown command: #{command}")
27
31
  end
28
32
 
29
- teardown
33
+ teardown
30
34
  end
31
35
 
32
36
  def init_and_exit(*argv)
@@ -6,7 +6,21 @@ module Turbine
6
6
  module StandardCommands
7
7
  include FileUtils
8
8
 
9
+ def setup
10
+ option_parser.on("--update", "Update") do
11
+ params[:update] = true
12
+ end
13
+ end
14
+
9
15
  def init
16
+ current_dir = File.dirname(__FILE__)
17
+
18
+ if params[:update] == true
19
+ update_standard_commands(current_dir)
20
+ prompt.say "Standard commands updated"
21
+ return
22
+ end
23
+
10
24
  mkdir_p(".turbine")
11
25
  mkdir_p(".turbine/log")
12
26
  mkdir_p(".turbine/commands")
@@ -17,8 +31,7 @@ module Turbine
17
31
  project_name = params[:arguments][1] || "default"
18
32
 
19
33
  raise if key.nil?
20
-
21
- current_dir = File.dirname(__FILE__)
34
+
22
35
 
23
36
  write_file("log/#{key}.json") { |f| f << [].to_json }
24
37
 
@@ -35,8 +48,14 @@ module Turbine
35
48
  f << { project_name => url }.to_json
36
49
  end
37
50
 
38
- cp_r("#{current_dir}/standard",
39
- "#{self.class.config_dir}/commands/")
51
+ update_standard_commands(current_dir)
52
+ end
53
+
54
+ private
55
+
56
+ def update_standard_commands(current_dir)
57
+ cp_r("#{current_dir}/standard",
58
+ "#{self.class.config_dir}/commands/")
40
59
  end
41
60
  end
42
- end
61
+ end
@@ -1,6 +1,11 @@
1
+ require 'tempfile'
2
+ require 'shellwords'
3
+
1
4
  Turbine::Application.extension do
2
5
  def commit
3
- if message = params[:message]
6
+ message = params[:message] || message_from_editor
7
+
8
+ if message && message != ""
4
9
  queue = Turbine::Queue.new
5
10
  duration = queue.sum.to_s
6
11
  timestamp = Time.now.utc.to_s
@@ -26,4 +31,24 @@ Turbine::Application.extension do
26
31
  prompt.say "You need to supply a message"
27
32
  end
28
33
  end
34
+
35
+ private
36
+
37
+ # Private launch the default editor to capture a commit message
38
+ #
39
+ # Uses the environment variable +MM_EDITOR+ if present, otherwise falls back
40
+ # to the default +EDITOR+ variable
41
+ #
42
+ # Returns text saved to the temp file
43
+ def message_from_editor
44
+ editor = ENV['MM_EDITOR'] || ENV['EDITOR']
45
+
46
+ return unless editor
47
+
48
+ Tempfile.open('commit.txt') do |file|
49
+ editor_invocation = "#{editor} #{file.path}"
50
+ system(*Shellwords.split(editor_invocation))
51
+ message = File.read(file.path)
52
+ end
53
+ end
29
54
  end
@@ -1,12 +1,13 @@
1
- Turbine::Application.extension do
1
+ Turbine::Application.extension do
2
2
  def status
3
3
  queue = Turbine::Queue.new
4
-
4
+
5
5
  if queue.empty?
6
6
  prompt.say "No entries for this commit yet\n\n"
7
7
  else
8
8
  entries = queue.entries.join(", ")
9
- sum = queue.entries.inject {|sum, n| sum + n }
9
+ sum = queue.entries.inject {|sum, n| sum + n }.
10
+ round(Turbine::PRECISION)
10
11
  prompt.say "Entries for this commit: ( #{entries} )"
11
12
  prompt.say "Total for this commit: #{sum}\n\n"
12
13
  end
data/lib/turbine/queue.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Turbine
2
- class Queue
2
+ class Queue
3
3
  include Enumerable
4
4
 
5
5
  def initialize(dir=Turbine::Application.config_dir)
@@ -18,7 +18,7 @@ module Turbine
18
18
  def entries
19
19
  return [] if empty?
20
20
 
21
- File.read(@file).split("\n").map { |e| e.to_f }
21
+ File.read(@file).split("\n").map { |e| e.to_f.round(Turbine::PRECISION) }
22
22
  end
23
23
 
24
24
  def each
@@ -30,7 +30,7 @@ module Turbine
30
30
 
31
31
  File.foreach(@file).inject(0) do |sum, line|
32
32
  sum + line.to_f
33
- end
33
+ end.round(Turbine::PRECISION)
34
34
  end
35
35
 
36
36
  def clear
data/lib/turbine/timer.rb CHANGED
@@ -13,14 +13,14 @@ module Turbine
13
13
  def write_timestamp
14
14
  File.open(@file, "w") { |f| f << Time.now.utc.to_s }
15
15
  end
16
-
16
+
17
17
  def timestamp
18
18
  raise MissingTimestampError unless running?
19
19
  Time.parse(File.read(@file)).localtime
20
20
  end
21
-
21
+
22
22
  def elapsed_time
23
- (Time.now.utc - timestamp.utc) / 60.0 / 60.0
23
+ ((Time.now.utc - timestamp.utc) / 60.0 / 60.0).round(Turbine::PRECISION)
24
24
  end
25
25
 
26
26
  def clear_timestamp
@@ -30,6 +30,6 @@ module Turbine
30
30
  def running?
31
31
  File.exist?(@file)
32
32
  end
33
- end
33
+ end
34
34
  end
35
35
 
metadata CHANGED
@@ -1,86 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mm
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Gregory Brown
9
+ - Jordan Byron
10
+ - Brad Ediger
14
11
  autorequire:
15
12
  bindir: bin
16
13
  cert_chain: []
17
-
18
- date: 2010-08-10 00:00:00 -04:00
19
- default_executable:
14
+ date: 2013-08-21 00:00:00.000000000 Z
20
15
  dependencies: []
21
-
22
- description: " Seeekrit\n"
23
- email: " gregory.t.brown@gmail.com"
24
- executables:
16
+ description: CLI for Madriska Momentum
17
+ email:
18
+ - gregory.t.brown@gmail.com
19
+ - jordan.byron@gmail.com
20
+ - brad@bradedier.com
21
+ executables:
25
22
  - mm
26
23
  extensions: []
27
-
28
24
  extra_rdoc_files: []
29
-
30
- files:
25
+ files:
31
26
  - lib/turbine/application.rb
32
27
  - lib/turbine/command_runner.rb
33
- - lib/turbine/timer.rb
34
- - lib/turbine/queue.rb
35
- - lib/turbine/commands/standard/staged.rb
36
- - lib/turbine/commands/standard/start.rb
28
+ - lib/turbine/commands/init.rb
37
29
  - lib/turbine/commands/standard/add.rb
38
- - lib/turbine/commands/standard/reset.rb
30
+ - lib/turbine/commands/standard/commit.rb
39
31
  - lib/turbine/commands/standard/drop.rb
40
- - lib/turbine/commands/standard/status.rb
32
+ - lib/turbine/commands/standard/project.rb
41
33
  - lib/turbine/commands/standard/push.rb
34
+ - lib/turbine/commands/standard/reset.rb
42
35
  - lib/turbine/commands/standard/rewind.rb
43
- - lib/turbine/commands/standard/project.rb
44
- - lib/turbine/commands/standard/commit.rb
36
+ - lib/turbine/commands/standard/staged.rb
37
+ - lib/turbine/commands/standard/start.rb
38
+ - lib/turbine/commands/standard/status.rb
45
39
  - lib/turbine/commands/standard/stop.rb
46
- - lib/turbine/commands/init.rb
40
+ - lib/turbine/queue.rb
41
+ - lib/turbine/timer.rb
47
42
  - lib/turbine.rb
48
43
  - data/config.rb.erb
49
44
  - bin/mm
50
45
  - Rakefile
51
- has_rdoc: true
52
- homepage: http://pixelpowerhouse.com
46
+ homepage: http://momentum.madriska.com
53
47
  licenses: []
54
-
55
48
  post_install_message:
56
49
  rdoc_options: []
57
-
58
- require_paths:
50
+ require_paths:
59
51
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
61
53
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
59
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
78
64
  requirements: []
79
-
80
65
  rubyforge_project:
81
- rubygems_version: 1.3.7
66
+ rubygems_version: 1.8.23
82
67
  signing_key:
83
68
  specification_version: 3
84
- summary: A seecret
69
+ summary: CLI for Madriska Momentum
85
70
  test_files: []
86
-