mothership 0.2.3 → 0.2.4

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.
@@ -22,8 +22,8 @@ class Mothership
22
22
  def given(name)
23
23
  if @inputs.key?(name)
24
24
  @inputs[name]
25
- else
26
- @given[name]
25
+ elsif (given = @given[name]) != :interact
26
+ given
27
27
  end
28
28
  end
29
29
 
@@ -43,11 +43,26 @@ class Mothership
43
43
  inputs.delete(n)
44
44
  end
45
45
 
46
- self.class.new(@command, @context, given, inputs, @global)
46
+ self.class.new(@command, @context, inputs, given, @global)
47
47
  end
48
48
 
49
49
  def [](name, *args)
50
- get(name, @context, *args)
50
+ return @inputs[name] if @inputs.key?(name)
51
+
52
+ if @command && meta = @command.inputs[name]
53
+ # special case so #invoke can be called with singular-named inputs
54
+ singular = meta[:singular]
55
+
56
+ if @inputs.key?(singular)
57
+ return @inputs[name] = [@inputs[singular]]
58
+ end
59
+ end
60
+
61
+ val = get(name, @context, *args)
62
+
63
+ @inputs[name] = val unless meta && meta[:forget]
64
+
65
+ val
51
66
  end
52
67
 
53
68
  def interact(name, *args)
@@ -71,16 +86,10 @@ class Mothership
71
86
  # 5. global
72
87
  # 6. global, singular
73
88
  def get(name, context, *args)
74
- return @inputs[name] if @inputs.key?(name)
75
-
76
89
  before_input = @current_input
77
90
  @current_input = [name, args]
78
91
 
79
92
  if @command && meta = @command.inputs[name]
80
- # special case so #invoke can be called with singular-named inputs
81
- singular = meta[:singular]
82
- return @inputs[name] = [@inputs[singular]] if @inputs.key?(singular)
83
-
84
93
  found, val = find_in(@given, name, meta, context, *args)
85
94
  elsif meta = Mothership.global_option(name)
86
95
  found, val = find_in(@global, name, meta, context, *args)
@@ -89,16 +98,15 @@ class Mothership
89
98
  return val if not found
90
99
 
91
100
  if val == :interact && interact = meta[:interact]
92
- @inputs[name] = context.instance_exec(*args, &interact)
101
+ context.instance_exec(*args, &interact)
93
102
  else
94
- @inputs[name] = convert_given(meta, context, val, *args)
103
+ convert_given(meta, context, val, *args)
95
104
  end
96
105
  ensure
97
106
  @current_input = before_input
98
107
  end
99
108
 
100
109
  def forget(name)
101
- @given.delete(name)
102
110
  @inputs.delete(name)
103
111
  end
104
112
 
@@ -117,12 +125,7 @@ class Mothership
117
125
  [true, [where[singular]]]
118
126
  else
119
127
  # no value given; set as default
120
- val = default_for(meta, context, *args)
121
-
122
- # cache default value
123
- @inputs[name] = val unless meta[:forget]
124
-
125
- [false, val]
128
+ [false, default_for(meta, context, *args)]
126
129
  end
127
130
  end
128
131
 
@@ -1,3 +1,3 @@
1
1
  class Mothership
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mothership
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-15 00:00:00 Z
18
+ date: 2012-10-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake