samovar 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/samovar/options.rb +22 -4
- data/lib/samovar/version.rb +1 -1
- data/{flopp.gemspec → samovar.gemspec} +0 -0
- data/spec/samovar/type_spec.rb +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7156fc30783791549f5bbaa24754f40a8d0836
|
4
|
+
data.tar.gz: 298a257e5ca921533bb24e407f18ebc978b27d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
- [
|
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
|
|
data/lib/samovar/options.rb
CHANGED
@@ -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 =
|
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
|
-
|
54
|
-
|
55
|
-
|
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)
|
data/lib/samovar/version.rb
CHANGED
File without changes
|
data/spec/samovar/type_spec.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|