peto 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/bin/peto CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/bin/ruby
2
2
 
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
5
  require "peto"
4
6
 
5
7
  peto = Peto::Master.new
@@ -57,7 +57,7 @@ module Peto
57
57
  end
58
58
 
59
59
  def each_procedures
60
- @contract["procedures"].each do |name, procedure|
60
+ (@contract["procedures"]||[]).each do |name, procedure|
61
61
  yield name.to_method_name, args(procedure["args"])
62
62
  (procedure["errors"]||[]).each do |error|
63
63
  yield "#{name} error #{error}".to_method_name, [arg("message", "string")]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Toshiyuki Hirooka
@@ -58,7 +58,6 @@ files:
58
58
  - test/contracts/loading.yml
59
59
  - test/helper.rb
60
60
  - test/test_peto.rb
61
- - examples/generated.rb
62
61
  has_rdoc: true
63
62
  homepage: http://github.com/tosik/peto
64
63
  licenses: []
@@ -94,4 +93,3 @@ summary: contract code generator
94
93
  test_files:
95
94
  - test/helper.rb
96
95
  - test/test_peto.rb
97
- - examples/generated.rb
@@ -1,151 +0,0 @@
1
- require "peto/mixin/peto_class"
2
- require "peto/mixin/peto_errorable"
3
-
4
- module Peto
5
- class TypeA
6
- include PetoClass
7
- def initialize(args={})
8
- @foo = nil
9
- @bar = nil
10
- @baz = [] # for Fixnum
11
-
12
- set_by_hash(args)
13
- raise_errors unless valid?
14
- end
15
-
16
- attr_reader :foo
17
- attr_reader :bar
18
- attr_reader :baz
19
-
20
- def members
21
- [:foo,:bar,:baz]
22
- end
23
-
24
- def types
25
- {:foo => Fixnum,:bar => String,:baz => Array}
26
- end
27
-
28
- def arrays
29
- {:baz => Fixnum}
30
- end
31
- end
32
- class TypeB
33
- include PetoClass
34
- def initialize(args={})
35
- @foo = nil
36
-
37
- set_by_hash(args)
38
- raise_errors unless valid?
39
- end
40
-
41
- attr_reader :foo
42
-
43
- def members
44
- [:foo]
45
- end
46
-
47
- def types
48
- {:foo => String}
49
- end
50
-
51
- def arrays
52
- {}
53
- end
54
- end
55
- class TypeC
56
- include PetoClass
57
- def initialize(args={})
58
- @foo = [] # for String
59
-
60
- set_by_hash(args)
61
- raise_errors unless valid?
62
- end
63
-
64
- attr_reader :foo
65
-
66
- def members
67
- [:foo]
68
- end
69
-
70
- def types
71
- {:foo => Array}
72
- end
73
-
74
- def arrays
75
- {:foo => String}
76
- end
77
- end
78
- end
79
-
80
- module Peto
81
- class Generating
82
- extend PetoErrorable
83
- def self.do_a(a,b,c)
84
- invalid_type("a", Fixnum, a) unless a.class == Fixnum
85
- invalid_type("b", String, b) unless b.class == String
86
- invalid_type("c", TypeB, c) unless c.class == TypeB
87
- raise_errors unless errors.empty?
88
-
89
- return {
90
- :procedure => "do_a",
91
- :args => {
92
- :a => hashize(a),
93
- :b => hashize(b),
94
- :c => hashize(c),
95
- }
96
- }
97
- end
98
-
99
- def self.do_a_error_not_found(message)
100
- invalid_type("message", String, message) unless message.class == String
101
- raise_errors unless errors.empty?
102
-
103
- return {
104
- :procedure => "do_a_error_not_found",
105
- :args => {
106
- :message => hashize(message),
107
- }
108
- }
109
- end
110
-
111
- def self.do_a_error_invalid_id(message)
112
- invalid_type("message", String, message) unless message.class == String
113
- raise_errors unless errors.empty?
114
-
115
- return {
116
- :procedure => "do_a_error_invalid_id",
117
- :args => {
118
- :message => hashize(message),
119
- }
120
- }
121
- end
122
-
123
- def self.do_b(a)
124
- invalid_type("a", TypeA, a) unless a.class == TypeA
125
- raise_errors unless errors.empty?
126
-
127
- return {
128
- :procedure => "do_b",
129
- :args => {
130
- :a => hashize(a),
131
- }
132
- }
133
- end
134
-
135
- def self.do_c()
136
- raise_errors unless errors.empty?
137
-
138
- return {
139
- :procedure => "do_c",
140
- :args => {
141
- }
142
- }
143
- end
144
-
145
-
146
- def self.hashize(var)
147
- return var if [Fixnum, String].include?(var.class)
148
- var.to_hash
149
- end
150
- end
151
- end