optopus 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +9 -7
  2. data/lib/optopus.rb +7 -7
  3. metadata +3 -3
data/README CHANGED
@@ -14,9 +14,8 @@ gem install optopus
14
14
  require 'optopus'
15
15
 
16
16
  opts = optopus do
17
- desc 'program information'
18
- option :info, '-I'
19
-
17
+ option :info, '-I', :desc => 'program information'
18
+
20
19
  desc 'print lots of debugging information'
21
20
  option :debug, '-d', '--debug'
22
21
 
@@ -24,23 +23,26 @@ gem install optopus
24
23
  option :output_file, '-o', '--output-file FILE', :default => '/var/log/xxx.log'
25
24
 
26
25
  desc 'set number of retries to NUMBER (0 unlimits)'
27
- option :tries, '-t', '--tries NUMBER', :type => Integer, :default => 0 do
26
+ option :tries, '-t', '--tries NUMBER', :type => Integer, :default => 0 do |value|
28
27
  # custom validation
29
- invalid_argument if @value < 0
28
+ invalid_argument if value < 0
30
29
  end
31
30
 
32
31
  desc 'comma-separated list of accepted extensions'
33
32
  option :accept, '-A', '--accept LIST', :type => Array, :default => []
34
33
 
34
+ desc 'access protocol'
35
+ option :protocol, '-P', '--protocol PROTO', :type => [:http, :ftp]
36
+
35
37
  desc 'access timestamp'
36
38
  option :timestamp, '-T', '--timestamp TIME', :type => Time
37
39
 
38
40
  # read yaml config file and overwrite options
39
41
  config_file '-c', '--config-file FILE'
40
42
 
41
- after do
43
+ after do |options|
42
44
  # postprocessing
43
- # @options.each { ... }
45
+ # options.each { ... }
44
46
  end
45
47
 
46
48
  error do |e|
data/lib/optopus.rb CHANGED
@@ -48,15 +48,15 @@ module Optopus
48
48
  end # DefinerContext
49
49
 
50
50
  class CheckerContext
51
- def self.evaluate(args, vars = {}, &block)
52
- self.new(args, vars).instance_eval(&block)
51
+ def self.evaluate(args, pass, &block)
52
+ self.new(args, &block).evaluate(pass)
53
53
  end
54
54
 
55
- def initialize(value, vars = {})
55
+ def initialize(value, &block)
56
56
  @args = value ? [value] : []
57
57
 
58
- vars.each do |name, value|
59
- instance_variable_set("@#{name}", value)
58
+ if block
59
+ (class<<self; self; end).send(:define_method, :evaluate, &block)
60
60
  end
61
61
  end
62
62
 
@@ -137,7 +137,7 @@ module Optopus
137
137
  @parser.on(*args) do |*v|
138
138
  value = v.first || true
139
139
  options[name] = value
140
- CheckerContext.evaluate(v, {:value => value}, &block) if block
140
+ CheckerContext.evaluate(v, value, &block) if block
141
141
  end
142
142
  end
143
143
 
@@ -187,7 +187,7 @@ module Optopus
187
187
  end
188
188
 
189
189
  @parser.parse!
190
- CheckerContext.evaluate([], {:options => options},&@on_after) if @on_after
190
+ CheckerContext.evaluate([], options, &@on_after) if @on_after
191
191
 
192
192
  return options
193
193
  rescue => e
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optopus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel