argh 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,9 +9,15 @@ module Argh
9
9
  instance_eval(&block)
10
10
  end
11
11
 
12
- def attribute(name, attribute = nil, &block)
12
+ def attribute(name, value = nil, &block)
13
+ attribute = nil
14
+ if value.is_a?(Symbol)
15
+ attribute = value
16
+ value = nil
17
+ end
13
18
  @attributes << {
14
19
  :name => name,
20
+ :value => value,
15
21
  :lambda => block || lambda { |i| i.send(attribute || name) }
16
22
  }
17
23
  end
@@ -8,18 +8,20 @@ module Argh
8
8
  @context = context
9
9
  end
10
10
 
11
+ def process
12
+ raise 'BaseFormatter should be subclassed'
13
+ end
14
+
15
+ private
16
+
11
17
  def attributes(&block)
12
18
  return enum_for(:attributes) unless block_given?
13
19
  @collector.attributes.each do |attr|
14
- value = @context.instance_eval(&attr[:lambda])
20
+ value = attr[:value] || @context.instance_eval(&attr[:lambda])
15
21
  yield attr[:name], value
16
22
  end
17
23
  end
18
24
 
19
- def process
20
- raise 'BaseFormatter should be subclassed'
21
- end
22
-
23
25
  end
24
26
 
25
27
  end
@@ -1,5 +1,5 @@
1
1
  module Argh
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  end
@@ -19,6 +19,10 @@ class BasicExample
19
19
  attribute :name
20
20
  end
21
21
 
22
+ argh 'straight' do
23
+ attribute :name, 'john'
24
+ end
25
+
22
26
  argh 'lambs' do
23
27
  attribute(:name) { name.reverse }
24
28
  end
@@ -69,6 +73,10 @@ describe Argh::Attributable do
69
73
  example.lambs.should == '-name \'izzeperC nhoJ\''
70
74
  end
71
75
 
76
+ it 'should be able to take straight arguments' do
77
+ example.straight.should == '-name \'john\''
78
+ end
79
+
72
80
  it 'should be able to specify a symbol instead of a lambda' do
73
81
  example.symb.should == '-the_name \'John Crepezzi\''
74
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-10-31 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -33,16 +33,16 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - lib/argh/attributable.rb
37
+ - lib/argh/collector.rb
36
38
  - lib/argh/formatters/base_formatter.rb
37
39
  - lib/argh/formatters/jcommander_formatter.rb
38
40
  - lib/argh/formatters.rb
39
- - lib/argh/attributable.rb
40
- - lib/argh/collector.rb
41
41
  - lib/argh/version.rb
42
42
  - lib/argh.rb
43
- - spec/spec_helper.rb
44
43
  - spec/examples/basic_spec.rb
45
44
  - spec/examples/jcommander_spec.rb
45
+ - spec/spec_helper.rb
46
46
  homepage: https://github.com/broadstreetads/argh
47
47
  licenses: []
48
48
  post_install_message:
@@ -68,6 +68,6 @@ signing_key:
68
68
  specification_version: 3
69
69
  summary: Easy command-line arguments
70
70
  test_files:
71
- - spec/spec_helper.rb
72
71
  - spec/examples/basic_spec.rb
73
72
  - spec/examples/jcommander_spec.rb
73
+ - spec/spec_helper.rb