gm 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/LICENSE.txt +22 -0
  2. data/README.textile +13 -0
  3. data/bin/gem-make +6 -0
  4. data/bin/gm +6 -0
  5. data/gm_behaviors/author_behavior.rb +29 -0
  6. data/gm_behaviors/bin_files_behavior.rb +10 -0
  7. data/gm_behaviors/dependencies_behavior.rb +22 -0
  8. data/gm_behaviors/executables_behavior.rb +13 -0
  9. data/gm_behaviors/general_behavior.rb +41 -0
  10. data/gm_behaviors/github_behavior.rb +11 -0
  11. data/gm_behaviors/gm_files_behavior.rb +13 -0
  12. data/gm_behaviors/lib_files_behavior.rb +10 -0
  13. data/gm_behaviors/rails_behavior.rb +11 -0
  14. data/gm_behaviors/rdoc_behavior.rb +34 -0
  15. data/gm_behaviors/rspec_behavior.rb +10 -0
  16. data/gm_behaviors/rubigen_behavior.rb +13 -0
  17. data/gm_behaviors/rubyforge_behavior.rb +12 -0
  18. data/gm_behaviors/test_behavior.rb +10 -0
  19. data/gm_behaviors/text_files_behavior.rb +10 -0
  20. data/gm_commands/build_command.rb +25 -0
  21. data/gm_commands/build_gemspec_command.rb +35 -0
  22. data/gm_commands/clean_command.rb +14 -0
  23. data/gm_commands/config_command.rb +42 -0
  24. data/gm_commands/create_command.rb +10 -0
  25. data/gm_commands/gen_command.rb +31 -0
  26. data/gm_commands/help_command.rb +246 -0
  27. data/gm_commands/install_command.rb +17 -0
  28. data/gm_commands/publish_command.rb +33 -0
  29. data/gm_commands/spec_command.rb +14 -0
  30. data/gm_generators/bin/bin_generator.rb +22 -0
  31. data/gm_generators/bin/templates/bin/bin.rb +3 -0
  32. data/gm_generators/gem/gem_generator.rb +38 -0
  33. data/gm_generators/gem/templates/Gmfile +4 -0
  34. data/gm_generators/gem/templates/README.textile +0 -0
  35. data/gm_generators/gem/templates/lib/module.rb +4 -0
  36. data/gm_generators/mit_license/mit_license_generator.rb +17 -0
  37. data/gm_generators/mit_license/templates/LICENSE.txt +22 -0
  38. data/gm_generators/rails/rails_generator.rb +18 -0
  39. data/gm_generators/rails/templates/rails/init.rb +1 -0
  40. data/gm_generators/test/templates/test_case.rb.erb +5 -0
  41. data/gm_generators/test/templates/test_helper.rb.erb +7 -0
  42. data/gm_generators/test/test_generator.rb +26 -0
  43. data/gm_networks/github_network.rb +72 -0
  44. data/gm_networks/rubyforge_network.rb +90 -0
  45. data/lib/autotest/discover.rb +3 -0
  46. data/lib/autotest/gm.rb +37 -0
  47. data/lib/extentions/gem.rb +27 -0
  48. data/lib/gm.rb +30 -0
  49. data/lib/gm/app.rb +108 -0
  50. data/lib/gm/behavior.rb +23 -0
  51. data/lib/gm/command.rb +70 -0
  52. data/lib/gm/configuration.rb +20 -0
  53. data/lib/gm/documentation.rb +38 -0
  54. data/lib/gm/helpers.rb +20 -0
  55. data/lib/gm/loader.rb +84 -0
  56. data/lib/gm/network.rb +29 -0
  57. data/lib/gm/system.rb +16 -0
  58. data/test/command_test.rb +106 -0
  59. data/test/gem_extentions_test.rb +31 -0
  60. data/test/system_test.rb +17 -0
  61. data/test/test_helper.rb +12 -0
  62. metadata +159 -0
@@ -0,0 +1,23 @@
1
+
2
+ module GM
3
+
4
+ class Behavior
5
+
6
+ include GM::Documentation
7
+ include GM::Configuration
8
+ include GM::Helpers
9
+ include GM::System
10
+ include GM::Loader
11
+
12
+ desc ""
13
+ doc ""
14
+
15
+ loads :behaviors
16
+
17
+ def run
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,70 @@
1
+
2
+ module GM
3
+
4
+ class Command
5
+
6
+ attr_accessor :argv
7
+ attr_accessor :options
8
+
9
+ include GM::Documentation
10
+ include GM::Configuration
11
+ include GM::Helpers
12
+ include GM::System
13
+ include GM::Loader
14
+
15
+ desc ""
16
+ doc ""
17
+ banner ""
18
+ loads :commands
19
+
20
+ # build a command
21
+ def self.run(cmd_name=nil, argv=ARGV)
22
+ app = GM.app
23
+ if Array === cmd_name
24
+ argv = cmd_name
25
+ cmd_name = nil
26
+ end
27
+ cmd = self.build(cmd_name, argv)
28
+ clip = Clip(argv) do |p|
29
+ p.banner = cmd.banner_text
30
+ app.extra_options(p)
31
+ cmd.extra_options(p)
32
+ end
33
+ app.log_level = :verbose if clip.verbose?
34
+ app.log_level = :debug if clip.debug?
35
+ cmd.options = clip
36
+ argv.clear
37
+ argv.concat(clip.remainder)
38
+ cmd.argv = argv
39
+ cmd.run
40
+ argv
41
+ end
42
+
43
+ # build a command
44
+ def self.build(cmd_name=nil, argv=ARGV)
45
+ if Array === cmd_name
46
+ argv = cmd_name
47
+ cmd_name = nil
48
+ end
49
+ if cmd_name.nil?
50
+ cmd_name = (argv.detect {|i| i !~ /^--?/ } || 'help')
51
+ argv.delete(cmd_name)
52
+ end
53
+ app = GM.app
54
+ cmd_name = cmd_name.to_s.underscore.to_sym
55
+ cmd_class = GM::Command.commands[cmd_name]
56
+ cmd_class ||= GM::Command.commands[:help]
57
+ cmd_class.new
58
+ end
59
+
60
+ # A command can overwrite this method in order to add extra command line options.
61
+ def extra_options(options)
62
+ end
63
+
64
+ # A command must overwrite this method.
65
+ def run
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module GM
3
+
4
+ module Configuration
5
+
6
+ def self.included(base)
7
+ base.extend GM::Configuration::ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def specify_conf(&block)
13
+ EC.store.specify(&block)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,38 @@
1
+
2
+ module GM
3
+
4
+ module Documentation
5
+
6
+ def self.included(base)
7
+ base.extend GM::Documentation::ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def desc(text)
12
+ module_eval %{
13
+ def self.description
14
+ ERB.new(#{text.inspect}).result(binding)
15
+ end
16
+ }
17
+ end
18
+ def doc(text)
19
+ module_eval %{
20
+ def self.documentation
21
+ ERB.new(#{text.inspect}).result(binding)
22
+ end
23
+ }
24
+ end
25
+ def banner(text)
26
+ text = "#{File.basename($0)} #{text}" unless text.blank?
27
+ module_eval %{
28
+ def self.banner_text
29
+ #{text.inspect}
30
+ end
31
+ def banner_text; self.class.banner_text ; end
32
+ }
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module GM
3
+
4
+ module Helpers
5
+
6
+ def app
7
+ GM.app
8
+ end
9
+
10
+ def config
11
+ EC.store.config
12
+ end
13
+
14
+ def spec
15
+ GM.app.gemspec
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,84 @@
1
+
2
+ module GM
3
+
4
+ module Loader
5
+
6
+ def self.included(base)
7
+ base.extend GM::Loader::Macros
8
+ end
9
+
10
+ module Macros
11
+
12
+ def loads(name, options={})
13
+ options.reverse_merge!(
14
+ :name => name.to_s.singularize.underscore,
15
+ :includes => [],
16
+ :extends => [],
17
+ :extention => ".rb",
18
+ :collection => name.to_s.pluralize.underscore,
19
+ :only_eval => false
20
+ )
21
+ options[:extends] = [options[:extends]].flatten
22
+ options[:includes] = [options[:includes]].flatten
23
+ unless options[:only_eval]
24
+ module_eval %{
25
+ extend GM::Loader::ClassMethods
26
+ def self.load_#{options[:name]}(path)
27
+ klass = load(path, #{options.inspect})
28
+ #{options[:collection]}[klass.name] = klass
29
+ klass
30
+ end
31
+ def self.name
32
+ return @name unless @name.nil?
33
+ regexp = /^(?:[#][<]Module[:]0x[0-9a-f]+[>][:]{2})?(.+)#{options[:name].camelize}$/
34
+ @name = self.to_s
35
+ @name.gsub!(regexp, '\\1')
36
+ @name = @name.underscore.to_sym
37
+ end
38
+ def self.#{options[:collection]}
39
+ @#{options[:collection]} ||= {}
40
+ end
41
+ }
42
+ else
43
+ module_eval %{
44
+ extend GM::Loader::ClassMethods
45
+ def self.load_#{options[:name]}(path)
46
+ load(path, #{options.inspect})
47
+ true
48
+ end
49
+ }
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ module ClassMethods
56
+
57
+ def load(path, options={})
58
+ raise LoadError, "file missing at path: #{path}" unless File.exist?(path)
59
+ cmd_name = File.basename(path, '.rb')
60
+ cmd_name = cmd_name.camelize
61
+
62
+ mod = Module.new
63
+ options[:includes].each do |mod|
64
+ mod.send :include, mod
65
+ end
66
+ options[:extends].each do |mod|
67
+ mod.send :extend, mod
68
+ end
69
+ mod.module_eval(IO.read(path), path)
70
+
71
+ unless options[:only_eval]
72
+ cmd_class = (mod.module_eval(cmd_name) rescue nil)
73
+
74
+ raise LoadError, "Expected file to define #{cmd_name} (#{path})" if cmd_class.nil?
75
+
76
+ cmd_class
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module GM
3
+
4
+ class Network
5
+
6
+ include GM::Documentation
7
+ include GM::Configuration
8
+ include GM::Helpers
9
+ include GM::System
10
+ include GM::Loader
11
+
12
+ desc ""
13
+ doc ""
14
+
15
+ loads :networks
16
+
17
+ def publish
18
+ end
19
+
20
+ def published_versions
21
+ end
22
+
23
+ def has_version?(version)
24
+ published_versions.include? version
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,16 @@
1
+
2
+ module GM
3
+
4
+ module System
5
+
6
+ def sh(*cmds)
7
+ cmds.each do |cmd|
8
+ cmd = cmd.strip
9
+ GM.app.log "> #{cmd}"
10
+ system(cmd)
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class CommandTest < Test::Unit::TestCase
4
+
5
+ before do
6
+ GM.app.reset!
7
+ end
8
+
9
+ context "load_command" do
10
+
11
+ should "return klass" do
12
+ File.expects(:exist?).with('path/to/my_command.rb').returns(true)
13
+ IO.expects(:read).with('path/to/my_command.rb').returns(%{
14
+ class MyCommand ; end
15
+ })
16
+ klass = GM::Command.load_command('path/to/my_command.rb')
17
+ assert_equal "MyCommand", klass.to_s.split('::', 2).last
18
+ end
19
+
20
+ should "return false when file doen't exist" do
21
+ File.expects(:exist?).with('path/to/my_command.rb').returns(false)
22
+ assert_raise(LoadError) { GM::Command.load_command('path/to/my_command.rb') }
23
+ end
24
+
25
+ should "return false when file doen't contain command" do
26
+ File.expects(:exist?).with('path/to/my_command.rb').returns(true)
27
+ IO.expects(:read).with('path/to/my_command.rb').returns(%{})
28
+ assert_raise(LoadError) { GM::Command.load_command('path/to/my_command.rb') }
29
+ end
30
+
31
+ end
32
+
33
+ context "build" do
34
+
35
+ should "return instance of HelpCommand not found" do
36
+ help_cmd = mock
37
+ help_cmd_class = mock
38
+ help_cmd_class.expects(:new).returns(help_cmd)
39
+ GM::Command.commands[:hello] = help_cmd_class
40
+ cmd = GM::Command.build(:hello)
41
+ assert_equal help_cmd, cmd
42
+ end
43
+
44
+ should "return new command" do
45
+ hello_cmd = mock
46
+ hello_cmd_class = mock
47
+ hello_cmd_class.expects(:new).returns(hello_cmd)
48
+ GM::Command.commands[:hello] = hello_cmd_class
49
+ cmd = GM::Command.build(:hello)
50
+ assert_equal hello_cmd, cmd
51
+ end
52
+
53
+ should "find command name in argv if name is nil" do
54
+ argv = %w( -v hello world )
55
+ hello_cmd = mock
56
+ hello_cmd_class = mock
57
+ hello_cmd_class.expects(:new).returns(hello_cmd)
58
+ GM::Command.commands[:hello] = hello_cmd_class
59
+ cmd = GM::Command.build(argv)
60
+ assert_equal hello_cmd, cmd
61
+ end
62
+
63
+ end
64
+
65
+ context "run" do
66
+
67
+ should "run command and return remaining argv" do
68
+ argv = %w( -v p )
69
+ hello_cmd = mock('hello_command') do
70
+ expects(:run)
71
+ expects(:banner_text).returns("")
72
+ expects(:extra_options).with() { |value| Clip::Parser === value }
73
+ expects(:options=).with() { |value| Clip::Parser === value }
74
+ expects(:argv=).with %w( p )
75
+ end
76
+ hello_cmd_class = mock('hello_command_class') do
77
+ expects(:new).returns(hello_cmd)
78
+ end
79
+ GM::Command.commands[:hello] = hello_cmd_class
80
+ assert_equal %w( p ), GM::Command.run(:hello, argv)
81
+ end
82
+
83
+ should "find command name in argv if name is nil" do
84
+ argv = %w( -v hello p )
85
+ hello_cmd = mock('hello_command') do
86
+ expects(:run)
87
+ expects(:banner_text).returns("")
88
+ expects(:extra_options).with() { |value| Clip::Parser === value }
89
+ expects(:options=).with() { |value| Clip::Parser === value }
90
+ expects(:argv=).with %w( p )
91
+ end
92
+ hello_cmd_class = mock('hello_command_class') do
93
+ expects(:new).returns(hello_cmd)
94
+ end
95
+ GM::Command.commands[:hello] = hello_cmd_class
96
+ assert_equal %w( p ), GM::Command.run(argv)
97
+ end
98
+
99
+ end
100
+
101
+
102
+ should "retrun GM.app for #app" do
103
+ assert_equal GM.app, GM::Command.new.send(:app)
104
+ end
105
+
106
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GemExtentionsTest < Test::Unit::TestCase
4
+
5
+ should "find recent files" do
6
+ gems = Gem.searcher.find_all('autotest/discover.rb')
7
+ gems = gems.inject({}) do |specs, spec|
8
+ specs[spec.name] = spec if specs[spec.name].nil? or (spec <=> specs[spec.name]) == 1
9
+ specs
10
+ end.values
11
+ paths = gems.collect do |gem|
12
+ Gem.searcher.matching_files gem, 'autotest/discover.rb'
13
+ end.flatten.compact
14
+
15
+ assert_equal paths, Gem.find_recent_files('autotest/discover.rb')
16
+ end
17
+
18
+ should "find_recent_resources" do
19
+ gems = Gem.searcher.find_all('autotest/discover.rb')
20
+ gems = gems.inject({}) do |specs, spec|
21
+ specs[spec.name] = spec if specs[spec.name].nil? or (spec <=> specs[spec.name]) == 1
22
+ specs
23
+ end.values
24
+ paths = gems.collect do |gem|
25
+ Gem.searcher.matching_files gem, 'autotest/discover.rb'
26
+ end.flatten.compact
27
+
28
+ assert_equal paths, Gem.find_recent_resources('lib/autotest/discover.rb')
29
+ end
30
+
31
+ end