linen 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,56 +10,56 @@
10
10
  require 'singleton'
11
11
 
12
12
  class Linen::PluginRegistry
13
- include Singleton
13
+ include Singleton
14
14
 
15
- include Enumerable
16
- def each
17
- ### yield the actual plugin object, which knows its own name
18
- @plugins.each { |name, plugin| yield plugin }
19
- end
15
+ include Enumerable
16
+ def each
17
+ ### yield the actual plugin object, which knows its own name
18
+ @plugins.each { |name, plugin| yield plugin }
19
+ end
20
20
 
21
21
 
22
- def register_plugin( plugin )
23
- raise Linen::Plugin::ArgumentError, "Attempted to register something that is not a Linen::Plugin" unless
24
- plugin < Linen::Plugin
22
+ def register_plugin( plugin )
23
+ raise Linen::Plugin::ArgumentError, "Attempted to register something that is not a Linen::Plugin" unless
24
+ plugin < Linen::Plugin
25
25
 
26
- @plugins ||= {}
27
- @plugins[ plugin.short_name ] = plugin
28
- end
29
- alias register register_plugin
30
- alias << register_plugin
26
+ @plugins ||= {}
27
+ @plugins[ plugin.short_name ] = plugin
28
+ end
29
+ alias register register_plugin
30
+ alias << register_plugin
31
31
 
32
32
 
33
- def size
34
- return @plugins.size
35
- end
33
+ def size
34
+ return @plugins.size
35
+ end
36
36
 
37
37
 
38
- def []( name )
39
- return @plugins[ name ]
40
- end
38
+ def []( name )
39
+ return @plugins[ name ]
40
+ end
41
41
 
42
42
 
43
- def commands
44
- if @commands.nil?
45
- ### create @commands. Each new key will get an empty array as its default value.
46
- @commands = IndifferentHash.new
43
+ def commands
44
+ if @commands.nil?
45
+ ### create @commands. Each new key will get an empty array as its default value.
46
+ @commands = IndifferentHash.new
47
47
 
48
- ### populates @commands as a hash of arrays. The hash key is the command name (.to_s) and the value
49
- ### is an array containing each plugin class in which that command is defined.
50
- @plugins.each do |name, plugin|
51
- plugin.commands.each do |name, cmd|
52
- @commands[ name ] ||= []
53
- @commands[ name ] << plugin
54
- end
55
- end
56
- end
48
+ ### populates @commands as a hash of arrays. The hash key is the command name (.to_s) and the value
49
+ ### is an array containing each plugin class in which that command is defined.
50
+ @plugins.each do |name, plugin|
51
+ plugin.commands.each do |name, cmd|
52
+ @commands[ name ] ||= []
53
+ @commands[ name ] << plugin
54
+ end
55
+ end
56
+ end
57
57
 
58
- return @commands
59
- end
58
+ return @commands
59
+ end
60
60
 
61
61
 
62
- def find_command( name )
63
- return @commands[ name ]
64
- end
62
+ def find_command( name )
63
+ return @commands[ name ]
64
+ end
65
65
  end
@@ -8,22 +8,22 @@
8
8
  ##############################################################
9
9
 
10
10
  class Linen::Workspace
11
- def set_value( name, value )
12
- # add getter
13
- (class << self ; self ; end).instance_eval {
14
- attr_reader name.to_s.intern
15
- }
11
+ def set_value( name, value )
12
+ # add getter
13
+ (class << self ; self ; end).instance_eval {
14
+ attr_reader name.to_s.intern
15
+ }
16
16
 
17
- # add ivar
18
- instance_variable_set "@#{name}", value
19
- end
17
+ # add ivar
18
+ instance_variable_set "@#{name}", value
19
+ end
20
20
 
21
- def add_values( hash )
22
- raise ArgumentError,
23
- "must send a hash" unless hash.is_a? Hash
21
+ def add_values( hash )
22
+ raise ArgumentError,
23
+ "must send a hash" unless hash.is_a? Hash
24
24
 
25
- hash.each do |k,v|
26
- self.set_value k, v
27
- end
28
- end
25
+ hash.each do |k,v|
26
+ self.set_value k, v
27
+ end
28
+ end
29
29
  end
@@ -8,8 +8,8 @@
8
8
  ##############################################################
9
9
 
10
10
  class String
11
- def wrap(line_width = 72)
12
- self.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
13
- end
11
+ def wrap(line_width = 72)
12
+ self.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
13
+ end
14
14
  end
15
15
 
@@ -12,100 +12,100 @@ require 'linen'
12
12
 
13
13
  class TestCLICommandCompletion < Test::Unit::TestCase
14
14
 
15
- ################
16
- # test plugins #
17
- ################
15
+ ################
16
+ # test plugins #
17
+ ################
18
18
 
19
- class ::TestPlugin < Linen::Plugin
20
- command :add do;end
21
- command :administer do;end
22
- command :somethingelse do;end
23
- end
19
+ class ::TestPlugin < Linen::Plugin
20
+ command :add do;end
21
+ command :administer do;end
22
+ command :somethingelse do;end
23
+ end
24
24
 
25
25
 
26
- class ::TeaPlugin < Linen::Plugin
27
- command :foo do;end
28
- end
26
+ class ::TeaPlugin < Linen::Plugin
27
+ command :foo do;end
28
+ end
29
29
 
30
30
 
31
- class ::OtherPlugin < Linen::Plugin
32
- command :food do;end
33
- end
31
+ class ::OtherPlugin < Linen::Plugin
32
+ command :food do;end
33
+ end
34
34
 
35
35
 
36
- #########
37
- # tests #
38
- #########
36
+ #########
37
+ # tests #
38
+ #########
39
39
 
40
- def test_plugin_completion
41
- all_plugins = Linen.plugins.map {|p| p.short_name}.sort
40
+ def test_plugin_completion
41
+ all_plugins = Linen.plugins.map {|p| p.short_name}.sort
42
42
 
43
- assert_raises_plugin_ambiguity_error( all_plugins ) do
44
- complete ''
45
- end
43
+ assert_raises_plugin_ambiguity_error( all_plugins ) do
44
+ complete ''
45
+ end
46
46
 
47
- assert_raises_plugin_ambiguity_error( all_plugins.select {|p| p =~ /^te/} ) do
48
- complete 'te'
49
- end
47
+ assert_raises_plugin_ambiguity_error( all_plugins.select {|p| p =~ /^te/} ) do
48
+ complete 'te'
49
+ end
50
50
 
51
- assert_nothing_raised do
52
- ### strip'ing because completion returns it with a trailing space
53
- assert_equal "test", complete( 'tes' ).strip
54
- end
55
- end
51
+ assert_nothing_raised do
52
+ ### strip'ing because completion returns it with a trailing space
53
+ assert_equal "test", complete( 'tes' ).strip
54
+ end
55
+ end
56
56
 
57
57
 
58
- def test_command_completion
59
- test_commands = Linen.plugins[ 'test' ].commands.keys.map {|k| k.to_s}.sort
58
+ def test_command_completion
59
+ test_commands = Linen.plugins[ 'test' ].commands.keys.map {|k| k.to_s}.sort
60
60
 
61
- assert_raises_command_ambiguity_error( test_commands ) do
62
- complete 'tes '
63
- end
61
+ assert_raises_command_ambiguity_error( test_commands ) do
62
+ complete 'tes '
63
+ end
64
64
 
65
- assert_raises_command_ambiguity_error( test_commands ) do
66
- complete 'test '
67
- end
65
+ assert_raises_command_ambiguity_error( test_commands ) do
66
+ complete 'test '
67
+ end
68
68
 
69
- starts_with_ad = test_commands.select {|c| c =~ /^ad/}
69
+ starts_with_ad = test_commands.select {|c| c =~ /^ad/}
70
70
 
71
- assert_raises_command_ambiguity_error( starts_with_ad ) do
72
- assert_equal "test ad", complete( 'test ad' )
73
- end
71
+ assert_raises_command_ambiguity_error( starts_with_ad ) do
72
+ assert_equal "test ad", complete( 'test ad' )
73
+ end
74
74
 
75
- assert_raises_command_ambiguity_error( starts_with_ad ) do
76
- assert_equal "test ad", complete( 'tes ad' )
77
- end
75
+ assert_raises_command_ambiguity_error( starts_with_ad ) do
76
+ assert_equal "test ad", complete( 'tes ad' )
77
+ end
78
78
 
79
- assert_nothing_raised do
80
- ### strip'ing because completion returns it with a trailing space
81
- assert_equal "test administer", complete( 'test adm' ).strip
82
- assert_equal "test administer", complete( 'tes adm' ).strip
83
- end
84
- end
79
+ assert_nothing_raised do
80
+ ### strip'ing because completion returns it with a trailing space
81
+ assert_equal "test administer", complete( 'test adm' ).strip
82
+ assert_equal "test administer", complete( 'tes adm' ).strip
83
+ end
84
+ end
85
85
 
86
86
 
87
- #######
88
- private
89
- #######
90
- def complete( str )
91
- return Linen::CLI.expand_command( str )
92
- end
87
+ #######
88
+ private
89
+ #######
90
+ def complete( str )
91
+ return Linen::CLI.expand_command( str )
92
+ end
93
93
 
94
- def assert_raises_ambiguity_error( exception, candidates, &block )
95
- begin
96
- block.call
97
- rescue exception => e
98
- assert_equal candidates, e.candidates
99
- else
100
- flunk 'no exception raised!'
101
- end
102
- end
94
+ def assert_raises_ambiguity_error( exception, candidates, &block )
95
+ begin
96
+ block.call
97
+ rescue exception => e
98
+ assert_equal candidates, e.candidates
99
+ else
100
+ flunk 'no exception raised!'
101
+ end
102
+ end
103
103
 
104
- def assert_raises_plugin_ambiguity_error( candidates, &block )
105
- assert_raises_ambiguity_error Linen::CLI::AmbiguousPluginError, candidates, &block
106
- end
104
+ def assert_raises_plugin_ambiguity_error( candidates, &block )
105
+ assert_raises_ambiguity_error Linen::CLI::AmbiguousPluginError, candidates, &block
106
+ end
107
107
 
108
- def assert_raises_command_ambiguity_error( candidates, &block )
109
- assert_raises_ambiguity_error Linen::CLI::AmbiguousCommandError, candidates, &block
110
- end
108
+ def assert_raises_command_ambiguity_error( candidates, &block )
109
+ assert_raises_ambiguity_error Linen::CLI::AmbiguousCommandError, candidates, &block
110
+ end
111
111
  end
@@ -11,41 +11,41 @@ require 'test/unit'
11
11
  require 'indifferent_hash'
12
12
 
13
13
  class TestIndifferentHash < Test::Unit::TestCase
14
- def setup
15
- @rhash = {
16
- :symbol => 'regular symbol',
17
- 'string' => 'regular string'
18
- }
14
+ def setup
15
+ @rhash = {
16
+ :symbol => 'regular symbol',
17
+ 'string' => 'regular string'
18
+ }
19
19
 
20
- @ihash = IndifferentHash.new
21
- @ihash[ :symbol ] = 'indifferent symbol'
22
- @ihash[ 'string' ] = 'indifferent string'
23
- end
20
+ @ihash = IndifferentHash.new
21
+ @ihash[ :symbol ] = 'indifferent symbol'
22
+ @ihash[ 'string' ] = 'indifferent string'
23
+ end
24
24
 
25
25
 
26
- def test_string_to_symbol_lookups
27
- key = 'symbol'
26
+ def test_string_to_symbol_lookups
27
+ key = 'symbol'
28
28
 
29
- assert_nil @rhash[ key ]
30
- assert_equal 'indifferent symbol', @ihash[ key ]
31
- end
29
+ assert_nil @rhash[ key ]
30
+ assert_equal 'indifferent symbol', @ihash[ key ]
31
+ end
32
32
 
33
33
 
34
- def test_symbol_to_string_lookups
35
- key = :string
34
+ def test_symbol_to_string_lookups
35
+ key = :string
36
36
 
37
- assert_nil @rhash[ key ]
38
- assert_equal 'indifferent string', @ihash[ key ]
39
- end
37
+ assert_nil @rhash[ key ]
38
+ assert_equal 'indifferent string', @ihash[ key ]
39
+ end
40
40
 
41
41
 
42
- def test_literal_key_priority
43
- ihash = IndifferentHash.new
42
+ def test_literal_key_priority
43
+ ihash = IndifferentHash.new
44
44
 
45
- ihash[ :key ] = "symbol"
46
- ihash[ 'key' ] = "string"
45
+ ihash[ :key ] = "symbol"
46
+ ihash[ 'key' ] = "string"
47
47
 
48
- assert_equal "symbol", ihash[ :key ]
49
- assert_equal "string", ihash[ 'key' ]
50
- end
48
+ assert_equal "symbol", ihash[ :key ]
49
+ assert_equal "string", ihash[ 'key' ]
50
+ end
51
51
  end
@@ -12,54 +12,54 @@ require 'linen'
12
12
 
13
13
  ### a little helper for later
14
14
  class String
15
- def to_regex
16
- return /#{self}/
17
- end
15
+ def to_regex
16
+ return /#{self}/
17
+ end
18
18
  end
19
19
 
20
20
 
21
21
  class TestPlugins < Test::Unit::TestCase
22
22
 
23
- ########################
24
- # "constant" variables #
25
- ########################
23
+ ########################
24
+ # "constant" variables #
25
+ ########################
26
26
 
27
- @description = "This is some descriptions"
28
- @help_msg = "This is some help messagesess"
29
- class << self
30
- attr_reader :description, :help_msg
31
- end
27
+ @description = "This is some descriptions"
28
+ @help_msg = "This is some help messagesess"
29
+ class << self
30
+ attr_reader :description, :help_msg
31
+ end
32
32
 
33
- ################
34
- # test plugins #
35
- ################
33
+ ################
34
+ # test plugins #
35
+ ################
36
36
 
37
- class ::HelpfulPlugin < Linen::Plugin
38
- puts TestPlugins.description
39
- description TestPlugins.description
37
+ class ::HelpfulPlugin < Linen::Plugin
38
+ puts TestPlugins.description
39
+ description TestPlugins.description
40
40
 
41
- command :test do
42
- help_message TestPlugins.help_msg
43
- end
44
- end
41
+ command :test do
42
+ help_message TestPlugins.help_msg
43
+ end
44
+ end
45
45
 
46
46
 
47
- class ::UnhelpfulPlugin < Linen::Plugin
48
- command :test do;end
49
- end
47
+ class ::UnhelpfulPlugin < Linen::Plugin
48
+ command :test do;end
49
+ end
50
50
 
51
- #########
52
- # tests #
53
- #########
51
+ #########
52
+ # tests #
53
+ #########
54
54
 
55
- def test_plugin_help
56
- assert HelpfulPlugin.help =~ TestPlugins.description.to_regex
57
- assert UnhelpfulPlugin.help =~ /No help for unhelpful/
58
- end
55
+ def test_plugin_help
56
+ assert HelpfulPlugin.help =~ TestPlugins.description.to_regex
57
+ assert UnhelpfulPlugin.help =~ /No help for unhelpful/
58
+ end
59
59
 
60
60
 
61
- def test_command_help
62
- assert HelpfulPlugin.commands[ :test ].help =~ TestPlugins.help_msg.to_regex
63
- assert UnhelpfulPlugin.commands[ :test ].help =~ /No help for unhelpful test/
64
- end
61
+ def test_command_help
62
+ assert HelpfulPlugin.commands[ :test ].help =~ TestPlugins.help_msg.to_regex
63
+ assert UnhelpfulPlugin.commands[ :test ].help =~ /No help for unhelpful test/
64
+ end
65
65
  end