samovar 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd4d6e27c6922df8e1c114c97ebb3960df04473
4
- data.tar.gz: 311072fee7aa41a8bb68cc36de8f7b3497c3c331
3
+ metadata.gz: 7a7156fc30783791549f5bbaa24754f40a8d0836
4
+ data.tar.gz: 298a257e5ca921533bb24e407f18ebc978b27d8e
5
5
  SHA512:
6
- metadata.gz: 49ca3a2ccefff661c04eede9d56c0904fa323987319093c321c419254f105e799698701bf699b0fee8c5bb73d9a414559def3c4ff2567397482066a16ac15464
7
- data.tar.gz: dd069406b3e275b2233f237961c9e46b287329d302fc23ed9849f069acd77a051cdd141c41a17622be9f4bc9ba2ef7b3c5e23a496049f4da0bd08c7c5cc74e7f
6
+ metadata.gz: c30c5704797b823905392e1ee6d76924980957bbaf8b581f240d3e35f84c4d09bb0a4155a2ce764f88e0ffeff90e948c778d1a16fff015051ba7ee98006e8be3
7
+ data.tar.gz: 8ca55afd6e7d32c2ee3da7171a2c39299f9aadfce9ef9faedd0d4d79421e8bef4b649e35b44a7c73abe10afd32070bede5364a9e153ca7a2b7604673aaf340fb
data/README.md CHANGED
@@ -18,7 +18,7 @@ One of the other issues I had with existing frameworks is testability. Most fram
18
18
 
19
19
  - [Teapot](https://github.com/ioquatix/teapot/blob/master/lib/teapot/command.rb) is a build system and uses multiple top-level commands.
20
20
  - [Utopia](https://github.com/ioquatix/utopia/blob/master/lib/utopia/command.rb) is a web application platform and uses nested commands.
21
- - [LSync](https://github.com/ioquatix/lsync/blob/master/lib/lsync/command.rb) is a backup tool and sends commands across the network and has lots of options with default values.
21
+ - [Synco](https://github.com/ioquatix/synco/blob/master/lib/synco/command.rb) is a backup tool and sends commands across the network and has lots of options with default values.
22
22
 
23
23
  ## Installation
24
24
 
@@ -34,10 +34,12 @@ module Samovar
34
34
 
35
35
  @default = default
36
36
 
37
+ # If the value is given, it overrides the user specified input.
37
38
  @value = value
38
39
  @value ||= true if @flags.boolean?
39
40
 
40
- @type = block_given? ? block : type
41
+ @type = type
42
+ @block = block
41
43
  end
42
44
 
43
45
  attr :flags
@@ -48,12 +50,28 @@ module Samovar
48
50
 
49
51
  attr :key
50
52
 
53
+ def coerce_type(result)
54
+ if @type == Integer
55
+ Integer(result)
56
+ elsif @type == Float
57
+ Float(result)
58
+ elsif @type.respond_to? :call
59
+ @type.call(result)
60
+ elsif @type.respond_to? :new
61
+ @type.new(result)
62
+ end
63
+ end
64
+
51
65
  def coerce(result)
52
66
  if @type
53
- @type.call(result)
54
- else
55
- result
67
+ result = coerce_type(result)
68
+ end
69
+
70
+ if @block
71
+ result = @block.call(result)
56
72
  end
73
+
74
+ return result
57
75
  end
58
76
 
59
77
  def parse(input)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Samovar
22
- VERSION = "1.2.0"
22
+ VERSION = "1.3.0"
23
23
  end
File without changes
@@ -8,13 +8,20 @@ module Command
8
8
  option '--things <array>', "A list of things" do |input|
9
9
  input.split(/\s*,\s*/)
10
10
  end
11
+
12
+ option '--count <integer>', "A number to count", type: Integer
11
13
  end
12
14
  end
13
15
  end
14
16
 
15
17
  describe Samovar::Command do
16
- it "should use default value" do
18
+ it "should coerce to array" do
17
19
  top = Command::Coerce.parse(['--things', 'a,b,c'])
18
20
  expect(top.options[:things]).to be == ['a', 'b', 'c']
19
21
  end
22
+
23
+ it "should coerce to integer" do
24
+ top = Command::Coerce.parse(['--count', '10'])
25
+ expect(top.options[:count]).to be == 10
26
+ end
20
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mapping
@@ -94,7 +94,6 @@ files:
94
94
  - Gemfile
95
95
  - README.md
96
96
  - Rakefile
97
- - flopp.gemspec
98
97
  - lib/samovar.rb
99
98
  - lib/samovar/command.rb
100
99
  - lib/samovar/command/system.rb
@@ -109,6 +108,7 @@ files:
109
108
  - lib/samovar/split.rb
110
109
  - lib/samovar/table.rb
111
110
  - lib/samovar/version.rb
111
+ - samovar.gemspec
112
112
  - spec/samovar/command_spec.rb
113
113
  - spec/samovar/type_spec.rb
114
114
  - teapot.png