obvious 0.0.5 → 0.0.6

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.
@@ -105,16 +105,18 @@ end
105
105
  @app.jacks.each do |k, v|
106
106
  name = k.chomp('Jack').downcase
107
107
  method_specs = ''
108
- method_defs = ''
108
+ contract_defs = ''
109
+
110
+ jack_double_default_methods = ''
111
+ jack_double_badoutput_methods = ''
109
112
 
110
113
  v.each do |method|
111
114
 
112
- method_defs << "
113
- def #{method}_contract input
114
- input_shape = {}
115
- output_shape = {}
116
- call_method :#{method}_alias, input, input_shape, output_shape
117
- end
115
+ contract_defs << "
116
+ contract_for :#{method}, {
117
+ :input => {},
118
+ :output => {},
119
+ }
118
120
  "
119
121
 
120
122
  method_specs << "
@@ -125,6 +127,18 @@ end
125
127
 
126
128
  it 'should raise an error with invalid output'
127
129
 
130
+ end
131
+ "
132
+
133
+ jack_double_default_methods << "
134
+ def #{method} input
135
+ {}
136
+ end
137
+ "
138
+
139
+ jack_double_badoutput_methods << "
140
+ def #{method} input
141
+ nil
128
142
  end
129
143
  "
130
144
  end
@@ -132,8 +146,7 @@ end
132
146
  output = %Q{require 'obvious'
133
147
 
134
148
  class #{k}Contract < Contract
135
- contracts :#{ v.join(', :')}
136
- #{method_defs}
149
+ #{contract_defs}
137
150
  end
138
151
  }
139
152
 
@@ -151,6 +164,32 @@ end
151
164
 
152
165
  filename = "#{@app.dir}/spec/contracts/#{snake_name}_jack_spec.rb"
153
166
  File.open(filename, 'w') {|f| f.write(output) }
167
+
168
+ output = %Q{require_relative '../../contracts/#{snake_name}_jack_contract'
169
+
170
+ class #{k}Double
171
+ def self.create behavior
172
+ case behavior
173
+ when :bad_output
174
+ #{k}_BadOutput.new
175
+ when :default
176
+ #{k}_Default.new
177
+ end
178
+ end
179
+ end
180
+
181
+ class #{k}_Default < #{k}Contract
182
+ #{jack_double_default_methods}
183
+ end
184
+
185
+ class #{k}_BadOutput < #{k}Contract
186
+ #{jack_double_badoutput_methods}
187
+ end
188
+ }
189
+
190
+ filename = "#{@app.dir}/spec/doubles/#{snake_name}_jack_double.rb"
191
+ File.open(filename, 'w') {|f| f.write(output) }
192
+
154
193
  end
155
194
  end # generate_jacks_code
156
195
  end
@@ -25,6 +25,34 @@ class Contract
25
25
  end
26
26
  end
27
27
 
28
+ # Public: Defines a contract for a method
29
+ #
30
+ # method - a symbol representing the method name
31
+ # contract - a hash with the keys :input and :output holding the respective shapes.
32
+ #
33
+ # Examples
34
+ #
35
+ # class FooJackContract < Contract
36
+ #
37
+ # contract_for :save, {
38
+ # :input => Foo.shape,
39
+ # :output => Foo.shape,
40
+ # }
41
+ #
42
+ # end
43
+ #
44
+ def self.contract_for method, contract
45
+ method_alias = "#{method}_alias".to_sym
46
+ method_contract = "#{method}_contract".to_sym
47
+
48
+ define_method method_contract do |*args|
49
+ input = args[0]
50
+ call_method method_alias, input, contract[:input], contract[:output]
51
+ end
52
+
53
+ contracts( *contract_list, method )
54
+ end
55
+
28
56
  # This method will move methods defined in @contracts into new methods.
29
57
  # Each entry in @contracts will cause the method with the same name to
30
58
  # become method_name_alias and for the original method to point to
@@ -1,3 +1,3 @@
1
1
  module Obvious
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obvious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A set of tools to build apps using the Obvious Architecture
15
15
  email: