peto 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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -5,5 +5,6 @@ require "animal"
5
5
  class FooController < ApplicationController
6
6
  def set_user(args)
7
7
  respond(123, "foo bar baz")
8
+ #error(:invalid_user, "aho #{args}")
8
9
  end
9
10
  end
@@ -15,11 +15,9 @@ module RailsApp
15
15
  # Custom directories with classes and modules you want to be autoloadable.
16
16
  # config.autoload_paths += %W(#{config.root}/extras)
17
17
 
18
- # local peto lib. you dont need it if you install peto by gem.
19
- config.autoload_paths += %W(#{config.root}/../../lib)
20
-
21
18
  # generated files by peto
22
19
  config.autoload_paths += %W(#{config.root}/contracts/generated)
20
+ #config.autoload_paths += %W(#{config.root}/../../lib)
23
21
 
24
22
  # Only load the plugins named here, in the order given (default is alphabetical).
25
23
  # :all can be used as a placeholder for all plugins not explicitly named.
@@ -4,20 +4,20 @@ module Peto
4
4
  class Animal
5
5
  include PetoClass
6
6
  def initialize(args={})
7
- @nme = nil
7
+ @name = nil
8
8
 
9
9
  set_by_hash(args)
10
10
  raise_errors unless valid?
11
11
  end
12
12
 
13
- attr_reader :nme
13
+ attr_reader :name
14
14
 
15
15
  def members
16
- [:nme]
16
+ [:name]
17
17
  end
18
18
 
19
19
  def types
20
- {:nme => String}
20
+ {:name => String}
21
21
  end
22
22
 
23
23
  def arrays
data/lib/peto/master.rb CHANGED
@@ -35,10 +35,10 @@ module Peto
35
35
  if File.read(filepath) == content
36
36
  print "identical".blue.bold
37
37
  else
38
- print "update ".white.bold
38
+ print " update".white.bold
39
39
  end
40
40
  else
41
- print "create ".green.bold
41
+ print " create".green.bold
42
42
  end
43
43
  print " "
44
44
 
@@ -36,7 +36,7 @@ module Peto
36
36
  end
37
37
 
38
38
  def error(error_name, *messages)
39
- call_procedure_response(:"error_#{error_name}", messages.join(","))
39
+ render(:json => call_procedure_response(:"error_#{error_name}", messages.join(",")))
40
40
  end
41
41
 
42
42
 
@@ -0,0 +1,45 @@
1
+ require "peto"
2
+ require "rake"
3
+ require "rake/tasklib"
4
+
5
+ module Peto
6
+ class RakeTask < ::Rake::TaskLib
7
+ attr_accessor :contracts
8
+ attr_accessor :output_dir
9
+ attr_accessor :name
10
+ attr_accessor :fail_on_error
11
+ attr_accessor :failure_message
12
+
13
+ def initialize(*args)
14
+ @contracts ||= []
15
+ @output_dir ||= "./"
16
+ @name ||= :peto
17
+ @fail_on_error ||= true
18
+
19
+ yield self if block_given?
20
+
21
+ desc("Generate codes by contracts") unless ::Rake.application.last_comment
22
+
23
+ task name do
24
+ RakeFileUtils.send(:verbose, verbose) do
25
+ if contracts.empty?
26
+ puts "No contracts"
27
+ else
28
+ begin
29
+ self.contracts = [contracts] if contracts.class == String
30
+ contracts.each do |contract|
31
+ peto = Peto::Master.new
32
+ peto.load(contract)
33
+ peto.generate(output_dir)
34
+ end
35
+ rescue
36
+ puts failure_message if failure_message
37
+ raise "peto failed" if fail_on_error
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Toshiyuki Hirooka
@@ -80,6 +80,7 @@ files:
80
80
  - lib/peto/mixin/peto_errorable.rb
81
81
  - lib/peto/rails/rails_controller_helper.rb
82
82
  - lib/peto/rails/rails_controller_test_helper.rb
83
+ - lib/peto/rake_task.rb
83
84
  - lib/templates/rb_classes.erb
84
85
  - lib/templates/rb_procedures.erb
85
86
  - test/contracts/generating.yml
@@ -108,14 +109,11 @@ files:
108
109
  - examples/rails_app/test/unit/helpers/foo_helper_test.rb
109
110
  - examples/rails_app/test/test_helper.rb
110
111
  - examples/rails_app/test/functional/foo_controller_test.rb
111
- - examples/rails_app/contracts/animal.rb
112
- - examples/rails_app/contracts/user.rb
113
112
  - examples/rails_app/contracts/generated/animal.rb
114
113
  - examples/rails_app/contracts/generated/aho.rb
115
114
  - examples/rails_app/contracts/generated/user.rb
116
115
  - examples/rails_app/contracts/generated/foo.rb
117
116
  - examples/rails_app/contracts/generated/iasdaho.rb
118
- - examples/rails_app/contracts/foo.rb
119
117
  has_rdoc: true
120
118
  homepage: http://github.com/tosik/peto
121
119
  licenses: []
@@ -173,11 +171,8 @@ test_files:
173
171
  - examples/rails_app/test/unit/helpers/foo_helper_test.rb
174
172
  - examples/rails_app/test/test_helper.rb
175
173
  - examples/rails_app/test/functional/foo_controller_test.rb
176
- - examples/rails_app/contracts/animal.rb
177
- - examples/rails_app/contracts/user.rb
178
174
  - examples/rails_app/contracts/generated/animal.rb
179
175
  - examples/rails_app/contracts/generated/aho.rb
180
176
  - examples/rails_app/contracts/generated/user.rb
181
177
  - examples/rails_app/contracts/generated/foo.rb
182
178
  - examples/rails_app/contracts/generated/iasdaho.rb
183
- - examples/rails_app/contracts/foo.rb
@@ -1,27 +0,0 @@
1
- require "peto/mixin/peto_class"
2
-
3
- module Peto
4
- class Animal
5
- include PetoClass
6
- def initialize(args={})
7
- @name = nil
8
-
9
- set_by_hash(args)
10
- raise_errors unless valid?
11
- end
12
-
13
- attr_reader :name
14
-
15
- def members
16
- [:name]
17
- end
18
-
19
- def types
20
- {:name => String}
21
- end
22
-
23
- def arrays
24
- {}
25
- end
26
- end
27
- end
@@ -1,36 +0,0 @@
1
- require "peto/mixin/peto_errorable"
2
-
3
- module Peto
4
- class Foo
5
- extend PetoErrorable
6
- def self.set_user(user)
7
- invalid_type("user", User, user) unless user.class == User
8
- raise_errors unless errors.empty?
9
-
10
- return {
11
- :procedure => "set_user",
12
- :args => {
13
- :user => hashize(user),
14
- }
15
- }
16
- end
17
-
18
- def self.set_user_error_invalid_user(message)
19
- invalid_type("message", String, message) unless message.class == String
20
- raise_errors unless errors.empty?
21
-
22
- return {
23
- :procedure => "set_user_error_invalid_user",
24
- :args => {
25
- :message => hashize(message),
26
- }
27
- }
28
- end
29
-
30
-
31
- def self.hashize(var)
32
- return var if [Fixnum, String].include?(var.class)
33
- var.to_hash
34
- end
35
- end
36
- end
@@ -1,31 +0,0 @@
1
- require "peto/mixin/peto_class"
2
-
3
- module Peto
4
- class User
5
- include PetoClass
6
- def initialize(args={})
7
- @name = nil
8
- @age = nil
9
- @animals = [] # for Animal
10
-
11
- set_by_hash(args)
12
- raise_errors unless valid?
13
- end
14
-
15
- attr_reader :name
16
- attr_reader :age
17
- attr_reader :animals
18
-
19
- def members
20
- [:name,:age,:animals]
21
- end
22
-
23
- def types
24
- {:name => String,:age => Fixnum,:animals => Array}
25
- end
26
-
27
- def arrays
28
- {:animals => Animal}
29
- end
30
- end
31
- end