acclaim 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,8 @@
1
- require 'acclaim/command/help'
2
- require 'acclaim/command/parser'
3
- require 'acclaim/command/version'
4
- require 'acclaim/option'
5
- require 'acclaim/option/parser'
6
- require 'acclaim/option/parser/regexp'
7
- require 'ribbon'
1
+ %w(option option/parser option/parser/regexp).each do |file|
2
+ require file.prepend 'acclaim/'
3
+ end
4
+
5
+ %w(ribbon ribbon/core_extensions/object).each { |file| require file }
8
6
 
9
7
  module Acclaim
10
8
 
@@ -104,9 +102,9 @@ module Acclaim
104
102
 
105
103
  # Invokes this command with a fresh set of option values.
106
104
  def run(*args)
107
- invoke Ribbon.new, args
108
- rescue Option::Parser::Error => e
109
- puts e.message
105
+ invoke args
106
+ rescue Option::Parser::Error => error
107
+ $stderr.puts error.message
110
108
  end
111
109
 
112
110
  # Parses the argument array. The argument array will be searched for
@@ -117,14 +115,15 @@ module Acclaim
117
115
  #
118
116
  # All argument separators will be deleted from the argument array before a
119
117
  # command is executed.
120
- def invoke(opts, args = [])
121
- Ribbon.merge! opts, parse_options!(args)
118
+ def invoke(args = [], opts = {})
119
+ opts = Ribbon.wrap opts
120
+ opts.merge! parse_options!(args)
122
121
  handle_special_options! opts, args
123
122
  if subcommand = parse_subcommands!(args)
124
- subcommand.invoke(opts, args)
123
+ subcommand.invoke args, opts
125
124
  else
126
125
  delete_argument_separators_in! args
127
- execute(opts, args)
126
+ execute opts, args
128
127
  end
129
128
  end
130
129
 
@@ -147,11 +146,6 @@ module Acclaim
147
146
  ancestors - Acclaim::Command.ancestors
148
147
  end
149
148
 
150
- # Progresively yields each command ancestor to the given block.
151
- def each_command_ancestor(&block)
152
- command_ancestors.each &block
153
- end
154
-
155
149
  # Returns the root of the command hierarchy.
156
150
  def root
157
151
  command_ancestors.last
@@ -190,7 +184,13 @@ module Acclaim
190
184
  def handle_special_options!(opts, args)
191
185
  const_get(:Help).execute opts, args if opts.acclaim_help?
192
186
  const_get(:Version).execute opts, args if opts.acclaim_version?
193
- # TODO: possibly rescue a NameError and warn user
187
+ # TODO:
188
+ # possibly rescue a NameError and warn user
189
+ # fix bug:
190
+ # calling this method causes a subcommand to be executed even if it
191
+ # wasn't given on the command line. This may result up to **three**
192
+ # commands (help, version and the actual command) running in one
193
+ # invocation.
194
194
  end
195
195
 
196
196
  # Deletes all argument separators in the given argument array.
@@ -212,3 +212,7 @@ module Acclaim
212
212
  end
213
213
 
214
214
  end
215
+
216
+ %w(help parser version).each do |command|
217
+ require command.prepend 'acclaim/command/'
218
+ end
@@ -1,72 +1,68 @@
1
1
  require 'acclaim/command/help/template'
2
- require 'ribbon/core_ext/array'
2
+ require 'ribbon/core_extensions/array'
3
3
 
4
4
  module Acclaim
5
5
  class Command
6
6
 
7
7
  # Module which adds help support to a command.
8
8
  module Help
9
+ end
9
10
 
10
- class << self
11
+ class << Help
11
12
 
12
- # Creates a help subcommand that inherits from the given +base+ command
13
- # and stores the class in the +Help+ constant of +base+. When called,
14
- # the command displays a help screen including information for all
15
- # commands and then exits.
16
- #
17
- # The last argument can be a configuration hash, which accepts the
18
- # following options:
19
- #
20
- # [:options] If +true+, will add a help option to the +base+
21
- # command.
22
- # [:switches] The switches used when creating the help option.
23
- # [:exit] If +true+, +exit+ will be called when the command is
24
- # done.
25
- # [:include_root] Includes the root command when displaying a command's
26
- # usage.
27
- def create(*args)
28
- opts, base = args.extract_ribbon!, args.shift
29
- add_options_to! base, opts if opts.options? true
30
- base.const_set(:Help, Class.new(base)).tap do |help_command|
31
- help_command.when_called do |options, args|
32
- # TODO: implement a way to specify a command to the help option
33
- # and command.
34
- # display_for options.command || args.pop
35
- display_for base.root, opts
36
- exit if opts.exit? true
37
- end
13
+ # Creates a help subcommand that inherits from the given +base+ command
14
+ # and stores the class in the +Help+ constant of +base+. When called, the
15
+ # command displays a help screen including information for all commands
16
+ # and then exits.
17
+ #
18
+ # The last argument can be a configuration hash, which accepts the
19
+ # following options:
20
+ #
21
+ # [:options] If +true+, will add a help option to the +base+
22
+ # command.
23
+ # [:switches] The switches used when creating the help option.
24
+ # [:include_root] Includes the root command when displaying a command's
25
+ # usage.
26
+ def create(*args)
27
+ opts, base = args.extract_ribbon!, args.shift
28
+ add_options_to! base, opts if opts.options? true
29
+ base.const_set(:Help, Class.new(base)).tap do |help_command|
30
+ help_command.when_called do |options, args|
31
+ # TODO: implement a way to specify a command to the help option
32
+ # and command.
33
+ # display_for options.command || args.pop
34
+ display_for base.root, opts
38
35
  end
39
36
  end
37
+ end
40
38
 
41
- # Displays a very simple help screen for the given command and all its
42
- # subcommands.
43
- #
44
- # The last argument can be a configuration hash, which accepts the
45
- # following options:
46
- #
47
- # [:include_root] Includes the root command when displaying a command's
48
- # usage.
49
- def display_for(*args)
50
- options, command = args.extract_ribbon!, args.shift
51
- puts Template.for(command, options) if command.options.any?
52
- command.subcommands.each { |subcommand| display_for(subcommand, options) }
53
- end
54
-
55
- private
39
+ # Displays a very simple help screen for the given command and all its
40
+ # subcommands.
41
+ #
42
+ # The last argument can be a configuration hash, which accepts the
43
+ # following options:
44
+ #
45
+ # [:include_root] Includes the root command when displaying a command's
46
+ # usage.
47
+ def display_for(*args)
48
+ options, command = args.extract_ribbon!, args.shift
49
+ puts Help::Template.for(command, options) if command.options.any?
50
+ command.subcommands.each { |subcommand| display_for(subcommand, options) }
51
+ end
56
52
 
57
- # Adds a special help option to the given +command+.
58
- #
59
- # The last argument can be a configuration hash, which accepts the
60
- # following options:
61
- #
62
- # [:switches] The switches used when creating the help option.
63
- def add_options_to!(*args)
64
- opts, command = args.extract_ribbon!, args.shift
65
- switches = opts.switches? { %w(-h --help) }
66
- description = opts.description? { 'Show usage information and exit.' }
67
- command.option :acclaim_help, *switches, description
68
- end
53
+ private
69
54
 
55
+ # Adds a special help option to the given +command+.
56
+ #
57
+ # The last argument can be a configuration hash, which accepts the
58
+ # following options:
59
+ #
60
+ # [:switches] The switches used when creating the help option.
61
+ def add_options_to!(*args)
62
+ opts, command = args.extract_ribbon!, args.shift
63
+ switches = opts.switches? { %w(-h --help) }
64
+ description = opts.description? { 'Show usage information and exit.' }
65
+ command.option :acclaim_help, *switches, description
70
66
  end
71
67
 
72
68
  end
@@ -1,5 +1,5 @@
1
1
  require 'erb'
2
- require 'ribbon/core_ext/array'
2
+ require 'ribbon/core_extensions/array'
3
3
 
4
4
  module Acclaim
5
5
  class Command
@@ -7,38 +7,37 @@ module Acclaim
7
7
 
8
8
  # Manages help templates.
9
9
  module Template
10
+ end
11
+
12
+ class << Template
13
+
14
+ # Returns the +template+ folder relative to this directory.
15
+ def folder
16
+ File.join File.dirname(__FILE__), 'template'
17
+ end
10
18
 
11
- class << self
12
-
13
- # Returns the +template+ folder relative to this directory.
14
- def folder
15
- File.join File.dirname(__FILE__), 'template'
16
- end
17
-
18
- # Loads the contents of a template file from the template #folder.
19
- def load(template_file)
20
- File.read File.join(folder, template_file)
21
- end
22
-
23
- # Creates a new ERB instance with the contents of +template+.
24
- def create_from(template_file)
25
- ERB.new load(template_file), nil, '%<>'
26
- end
27
-
28
- # Computes the result of the template +file+ using the +command+'s
29
- # binding.
30
- def for(*args)
31
- template_options, command = args.extract_ribbon!, args.shift
32
- template = create_from template_options.file?('command.erb')
33
- b = command.instance_eval { binding }
34
- # Since blocks are closures, the binding has access to the
35
- # template_options ribbon:
36
- #
37
- # p b.eval 'template_options'
38
- # => {}
39
- template.result b
40
- end
19
+ # Loads the contents of a template file from the template #folder.
20
+ def load(template_file)
21
+ File.read File.join(folder, template_file)
22
+ end
23
+
24
+ # Creates a new ERB instance with the contents of +template+.
25
+ def create_from(template_file)
26
+ ERB.new load(template_file), nil, '%<>'
27
+ end
41
28
 
29
+ # Computes the result of the template +file+ using the +command+'s
30
+ # binding.
31
+ def for(*args)
32
+ template_options, command = args.extract_ribbon!, args.shift
33
+ template = create_from template_options.file? 'command.erb'
34
+ command_binding = command.instance_eval { binding }
35
+ # Since blocks are closures, the binding has access to the
36
+ # template_options ribbon:
37
+ #
38
+ # p command_binding.eval 'template_options'
39
+ # => {}
40
+ template.result command_binding
42
41
  end
43
42
 
44
43
  end
@@ -1,52 +1,47 @@
1
- require 'ribbon/core_ext/array'
1
+ require 'ribbon/core_extensions/array'
2
2
 
3
3
  module Acclaim
4
4
  class Command
5
5
 
6
6
  # Module which adds version query support to a command.
7
7
  module Version
8
+ end
8
9
 
9
- class << self
10
-
11
- # Creates a <tt>version</tt> subcommand that inherits from the given
12
- # +base+ command and stores the class in the +Version+ constant of
13
- # +base+. When called, the command displays the +version_string+ of the
14
- # program and then exits.
15
- #
16
- # The last argument can be a configuration hash, which accepts the
17
- # following options:
18
- #
19
- # [:options] If +true+, will add a version option to the +base+
20
- # command.
21
- # [:switches] The switches used when creating the version option.
22
- # [:exit] If +true+, +exit+ will be called when the command is
23
- # done.
24
- def create(*args)
25
- opts, base, version_string = args.extract_ribbon!, args.shift, args.shift
26
- add_options_to! base, opts if opts.options? true
27
- base.const_set(:Version, Class.new(base)).tap do |version_command|
28
- version_command.when_called do |options, args|
29
- puts version_string
30
- exit if opts.exit? true
31
- end
10
+ class << Version
11
+
12
+ # Creates a <tt>version</tt> subcommand that inherits from the given
13
+ # +base+ command and stores the class in the +Version+ constant of +base+.
14
+ # When called, the command displays the +version_string+ of the program
15
+ # and then exits.
16
+ #
17
+ # The last argument can be a configuration hash, which accepts the
18
+ # following options:
19
+ #
20
+ # [:options] If +true+, will add a version option to the +base+ command.
21
+ # [:switches] The switches used when creating the version option.
22
+ def create(*args)
23
+ opts, base, version_string = args.extract_ribbon!, args.shift, args.shift
24
+ add_options_to! base, opts if opts.options? true
25
+ base.const_set(:Version, Class.new(base)).tap do |version_command|
26
+ version_command.when_called do |options, args|
27
+ puts version_string
32
28
  end
33
29
  end
30
+ end
34
31
 
35
- private
36
-
37
- # Adds a special version option to the given +command+.
38
- #
39
- # The last argument can be a configuration hash, which accepts the
40
- # following options:
41
- #
42
- # [:switches] The switches used when creating the version option.
43
- def add_options_to!(*args)
44
- opts, command = args.extract_ribbon!, args.shift
45
- switches = opts.switches? { %w(-v --version) }
46
- description = opts.description? { 'Show version and exit.' }
47
- command.option :acclaim_version, *switches, description
48
- end
49
-
32
+ private
33
+
34
+ # Adds a special version option to the given +command+.
35
+ #
36
+ # The last argument can be a configuration hash, which accepts the
37
+ # following options:
38
+ #
39
+ # [:switches] The switches used when creating the version option.
40
+ def add_options_to!(*args)
41
+ opts, command = args.extract_ribbon!, args.shift
42
+ switches = opts.switches? { %w(-v --version) }
43
+ description = opts.description? { 'Show version and exit.' }
44
+ command.option :acclaim_version, *switches, description
50
45
  end
51
46
 
52
47
  end
@@ -1,8 +1,9 @@
1
- require 'acclaim/option/arity'
2
- require 'acclaim/option/parser/regexp'
3
- require 'acclaim/option/type'
1
+ %w(arity parser/regexp type).each do |file|
2
+ require file.prepend 'acclaim/option/'
3
+ end
4
+
4
5
  require 'ribbon'
5
- require 'ribbon/core_ext/array'
6
+ %w(array hash).each { |file| require file.prepend 'ribbon/core_extensions/' }
6
7
 
7
8
  module Acclaim
8
9
 
@@ -16,7 +17,7 @@ module Acclaim
16
17
  attr_accessor :names
17
18
 
18
19
  # The description of this option.
19
- attr_accessor :description
20
+ attr_writer :description
20
21
 
21
22
  # The type the option's value will be converted to. See Option::Type.
22
23
  attr_accessor :type
@@ -54,12 +55,14 @@ module Acclaim
54
55
  # [:arity] The number of required and optional arguments. See Arity
55
56
  # for defails. Defaults to no arguments.
56
57
  # [:default] The default value for this option. Defaults to +nil+.
58
+ # [:description] The description. Overrides the one given among the other
59
+ # arguments.
57
60
  # [:required] Whether or not the option must be present on the command
58
61
  # line. Default is +false+.
59
62
  # [:on_multiple] What to do if the option is encountered multiple times.
60
- # Supported modes are <tt>:replace</tt>, <tt>:append</tt>
61
- # and <tt>:raise</tt>. New values will replace old ones by
62
- # default.
63
+ # Supported modes are <tt>:replace</tt>, <tt>:raise</tt> and
64
+ # <tt>:append</tt> (or <tt>:collect</tt>). New values will
65
+ # replace old ones by default.
63
66
  #
64
67
  # Additionally, if a block is given, it will be called when the option is
65
68
  # parsed with a ribbon instance and the parameters given to the option. The
@@ -68,27 +71,29 @@ module Acclaim
68
71
  # registering a custom type handler.
69
72
  def initialize(key, *args, &block)
70
73
  options = args.extract_ribbon!
71
- matches = args.select do |arg|
74
+ type = args.find { |arg| arg.is_a? Module }
75
+
76
+ strings = args.flatten.select do |arg|
72
77
  arg.is_a? String
73
78
  end.group_by do |arg|
74
- arg =~ Parser::Regexp::SWITCH ? true : false
75
- end
76
- klass = args.find { |arg| arg.is_a? Module }
77
- self.key = key
78
- self.names = matches.fetch(true) { [ Option.name_from(key) ] }
79
- self.description = matches.fetch(false, []).first
79
+ arg =~ Parser::Regexp::SWITCH ? :switches : :description
80
+ end.to_ribbon
81
+
82
+ self.key = key
83
+ self.names = strings.switches? { [ Option.name_from(key) ] }
84
+ self.description = options.description? strings.description?([]).first
80
85
  self.on_multiple = options.on_multiple? :replace
81
- self.arity = options.arity?
82
- self.default = options.default?
83
- self.required = options.required?
84
- self.type = klass || String
85
- self.handler = block
86
+ self.arity = options.arity?
87
+ self.default = options.default?
88
+ self.required = options.required?
89
+ self.type = type || String
90
+ self.handler = block
86
91
  end
87
92
 
88
93
  # Converts all given arguments using the type handler for this option's
89
94
  # type.
90
95
  def convert_parameters(*args)
91
- args.map { |arg| Type[type].call arg }
96
+ args.map { |arg| Type.handler_for(type).call arg }
92
97
  end
93
98
 
94
99
  # Returns true if the given string is equal to any of this option's names.
@@ -111,6 +116,12 @@ module Acclaim
111
116
  end
112
117
  end
113
118
 
119
+ # The description of this option. If it responds to +call+, it will be
120
+ # called to determine the description at runtime.
121
+ def description
122
+ (@description.respond_to?(:call) ? @description.call : @description).to_s
123
+ end
124
+
114
125
  # Whether or not this option is required on the command line.
115
126
  def required?
116
127
  @required
@@ -118,7 +129,7 @@ module Acclaim
118
129
 
119
130
  # Sets whether or not this option is required.
120
131
  def required=(value)
121
- @required = (value ? true : false)
132
+ @required = value ? true : false
122
133
  end
123
134
 
124
135
  # Require that this option be given on the command line.
@@ -140,22 +151,22 @@ module Acclaim
140
151
  # Same as <tt>flag?</tt>
141
152
  alias switch? flag?
142
153
 
143
- class << self
144
-
145
- # Derives a name from the given key's string representation. All
146
- # underscores will be replaced with dashes.
147
- #
148
- # If the string is empty, an +ArgumentError+ will be raised. If the
149
- # resulting name is not a valid switch, a +NameError+ will be raised.
150
- def name_from(key)
151
- name = key.to_s
152
- raise ArgumentError, "Can't derive name from empty key." if name.empty?
153
- name = (name.length == 1 ? '-' : '--') + name
154
- name.gsub! '_', '-'
155
- raise NameError, "Derived name is invalid: #{name}" unless name =~ Parser::Regexp::SWITCH
156
- name
157
- end
154
+ end
158
155
 
156
+ class << Option
157
+
158
+ # Derives a name from the given key's string representation. All
159
+ # underscores will be replaced with dashes.
160
+ #
161
+ # If the string is empty, an +ArgumentError+ will be raised. If the
162
+ # resulting name is not a valid switch, a +NameError+ will be raised.
163
+ def name_from(key)
164
+ name = key.to_s
165
+ raise ArgumentError, "Can't derive name from empty key." if name.empty?
166
+ name = (name.length == 1 ? '-' : '--') + name
167
+ name.gsub! '_', '-'
168
+ raise NameError, "Derived name is invalid: #{name}" unless name =~ Option::Parser::Regexp::SWITCH
169
+ name
159
170
  end
160
171
 
161
172
  end
@@ -1,5 +1,5 @@
1
- require 'acclaim/option/parser/error'
2
- require 'acclaim/option/parser/regexp'
1
+ %w(error regexp).each { |file| require file.prepend 'acclaim/option/parser/' }
2
+
3
3
  require 'ribbon'
4
4
 
5
5
  module Acclaim
@@ -103,7 +103,7 @@ module Acclaim
103
103
  end
104
104
  end
105
105
  end
106
- values.ribbon
106
+ values
107
107
  end
108
108
 
109
109
  # Finds the +switch+ in #argv and scans the next +option.arity.total+
@@ -154,7 +154,7 @@ module Acclaim
154
154
  else
155
155
  key = option.key
156
156
  value = option.arity.total == 1 ? params.first : params
157
- value = [*ribbon[key], *value] if option.on_multiple == :append
157
+ value = [*ribbon[key], *value] if [:append, :collect].include? option.on_multiple
158
158
  ribbon[key] = value unless params.empty?
159
159
  end
160
160
  end
@@ -3,55 +3,54 @@ module Acclaim
3
3
 
4
4
  # Associates a class with a handler block.
5
5
  module Type
6
+ end
6
7
 
7
- # The class methods.
8
- class << self
8
+ # The class methods.
9
+ class << Type
9
10
 
10
- # Yields class, proc pairs if a block was given. Returns an enumerator
11
- # otherwise.
12
- def each(&block)
13
- table.each &block
14
- end
11
+ # Yields class, proc pairs if a block was given. Returns an enumerator
12
+ # otherwise.
13
+ def each(&block)
14
+ table.each &block
15
+ end
15
16
 
16
- # Take advantage of each method.
17
- include Enumerable
17
+ # Take advantage of each method.
18
+ include Enumerable
18
19
 
19
- # Returns all registered classes.
20
- def all
21
- table.keys
22
- end
20
+ # Returns all registered classes.
21
+ def all
22
+ table.keys
23
+ end
23
24
 
24
- # Registers a handler for a class.
25
- def register(klass, &block)
26
- table[klass] = block
27
- end
25
+ # Registers a handler for a class.
26
+ def register(*klasses, &block)
27
+ klasses.each { |klass| table[klass] = block }
28
+ end
28
29
 
29
- # Returns the handler for the given class.
30
- def handler_for(klass)
31
- table.fetch klass do
32
- raise "#{klass} does not have an associated handler"
33
- end
30
+ # Returns the handler for the given class.
31
+ def handler_for(klass)
32
+ table.fetch klass do
33
+ raise "#{klass} does not have an associated handler"
34
34
  end
35
+ end
35
36
 
36
- # Same as <tt>all</tt>.
37
- alias registered all
38
-
39
- # Same as <tt>register</tt>.
40
- alias add_handler_for register
37
+ # Same as <tt>all</tt>.
38
+ alias registered all
41
39
 
42
- # Same as <tt>register</tt>.
43
- alias accept register
40
+ # Same as <tt>register</tt>.
41
+ alias add_handler_for register
44
42
 
45
- # Same as <tt>handler_for</tt>.
46
- alias [] handler_for
43
+ # Same as <tt>register</tt>.
44
+ alias accept register
47
45
 
48
- private
46
+ # Same as <tt>handler_for</tt>.
47
+ alias [] handler_for
49
48
 
50
- # The hash used to associate classes with their handlers.
51
- def table
52
- @table ||= {}
53
- end
49
+ private
54
50
 
51
+ # The hash used to associate classes with their handlers.
52
+ def table
53
+ @table ||= {}
55
54
  end
56
55
 
57
56
  end
@@ -59,6 +58,6 @@ module Acclaim
59
58
  end
60
59
  end
61
60
 
62
- %w(date date_time string symbol time uri).each do |type|
61
+ %w(big_decimal complex date date_time float integer rational string symbol time uri).each do |type|
63
62
  require type.prepend 'acclaim/option/type/'
64
63
  end
@@ -0,0 +1,22 @@
1
+ require 'acclaim/option/type'
2
+ require 'bigdecimal'
3
+
4
+ module Acclaim
5
+ class Option
6
+ module Type
7
+
8
+ # Handles big decimals given as arguments in the command line.
9
+ module BigDecimal
10
+
11
+ # Returns +BigDecimal.new(str)+.
12
+ def self.handle(str)
13
+ ::BigDecimal.new str
14
+ end
15
+
16
+ end
17
+
18
+ self.accept ::BigDecimal, &BigDecimal.method(:handle)
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'acclaim/option/type'
2
+
3
+ module Acclaim
4
+ class Option
5
+ module Type
6
+
7
+ # Handles complex numbers given as arguments in the command line.
8
+ module Complex
9
+
10
+ # Simply returns +str.to_c+.
11
+ def self.handle(str)
12
+ str.to_c
13
+ end
14
+
15
+ end
16
+
17
+ self.accept ::Complex, &Complex.method(:handle)
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'acclaim/option/type'
2
+
3
+ module Acclaim
4
+ class Option
5
+ module Type
6
+
7
+ # Handles floating point numbers given as arguments in the command line.
8
+ module Float
9
+
10
+ # Simply returns +str.to_f+.
11
+ def self.handle(str)
12
+ str.to_f
13
+ end
14
+
15
+ end
16
+
17
+ self.accept ::Float, &Float.method(:handle)
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'acclaim/option/type'
2
+
3
+ module Acclaim
4
+ class Option
5
+ module Type
6
+
7
+ # Handles integers given as arguments in the command line.
8
+ module Integer
9
+
10
+ # Simply returns +str.to_i+.
11
+ def self.handle(str)
12
+ str.to_i
13
+ end
14
+
15
+ end
16
+
17
+ self.accept ::Integer, &Integer.method(:handle)
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'acclaim/option/type'
2
+
3
+ module Acclaim
4
+ class Option
5
+ module Type
6
+
7
+ # Handles rational numbers given as arguments in the command line.
8
+ module Rational
9
+
10
+ # Simply returns +str.to_r+.
11
+ def self.handle(str)
12
+ str.to_r
13
+ end
14
+
15
+ end
16
+
17
+ self.accept ::Rational, &Rational.method(:handle)
18
+
19
+ end
20
+ end
21
+ end
@@ -11,12 +11,12 @@ module Acclaim
11
11
  # Minor version.
12
12
  #
13
13
  # Increments denote backward-compatible changes and additions.
14
- MINOR = 2
14
+ MINOR = 3
15
15
 
16
16
  # Patch version.
17
17
  #
18
18
  # Increments denote changes in implementation.
19
- PATCH = 3
19
+ PATCH = 0
20
20
 
21
21
  # Build version.
22
22
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ribbon
@@ -85,8 +85,13 @@ files:
85
85
  - lib/acclaim/option/parser/error.rb
86
86
  - lib/acclaim/option/parser/regexp.rb
87
87
  - lib/acclaim/option/type.rb
88
+ - lib/acclaim/option/type/big_decimal.rb
89
+ - lib/acclaim/option/type/complex.rb
88
90
  - lib/acclaim/option/type/date.rb
89
91
  - lib/acclaim/option/type/date_time.rb
92
+ - lib/acclaim/option/type/float.rb
93
+ - lib/acclaim/option/type/integer.rb
94
+ - lib/acclaim/option/type/rational.rb
90
95
  - lib/acclaim/option/type/string.rb
91
96
  - lib/acclaim/option/type/symbol.rb
92
97
  - lib/acclaim/option/type/time.rb
@@ -111,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
116
  version: '0'
112
117
  segments:
113
118
  - 0
114
- hash: -3961771875420064857
119
+ hash: 2327924451788950921
115
120
  required_rubygems_version: !ruby/object:Gem::Requirement
116
121
  none: false
117
122
  requirements:
@@ -120,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
125
  version: '0'
121
126
  segments:
122
127
  - 0
123
- hash: -3961771875420064857
128
+ hash: 2327924451788950921
124
129
  requirements: []
125
130
  rubyforge_project:
126
131
  rubygems_version: 1.8.21