toast 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -9
- data/lib/toast/active_record_extensions.rb +2 -2
- data/lib/toast/association.rb +20 -3
- data/lib/toast/version.rb +1 -1
- metadata +55 -88
data/README.md
CHANGED
@@ -2,7 +2,7 @@ Summary
|
|
2
2
|
=======
|
3
3
|
|
4
4
|
Toast is an extension to Ruby on Rails to build web services with low
|
5
|
-
programming effort in a coherent way. Toast
|
5
|
+
programming effort in a coherent way. Toast extends ActiveRecord such
|
6
6
|
that each model can be declared to be a web resource, exposing defined
|
7
7
|
attributes for reading and writing using HTTP.
|
8
8
|
|
@@ -11,14 +11,16 @@ Its main features are:
|
|
11
11
|
* declaration of web resources based on ActiveRecord models
|
12
12
|
* generic controller handles all actions
|
13
13
|
* automated routing
|
14
|
-
* exposing data values with JSON maps
|
14
|
+
* exposing data values with JSON maps
|
15
15
|
* exposing associations by links (URLs)
|
16
16
|
|
17
|
-
Toast works with
|
17
|
+
Toast works with
|
18
18
|
|
19
|
-
* Ruby on Rails >= 3.1.0 (currently tested up to 3.2.
|
19
|
+
* Ruby on Rails >= 3.1.0 (currently tested up to 3.2.8)
|
20
20
|
* Ruby 1.8.7 and 1.9.3
|
21
21
|
|
22
|
+
See the [User Manual](https://github.com/robokopp/toast/wiki/User-Manual) for a detailed description.
|
23
|
+
|
22
24
|
WARNING
|
23
25
|
=======
|
24
26
|
|
@@ -28,7 +30,7 @@ enabled serving the annotated model's data records.
|
|
28
30
|
|
29
31
|
Version 1.0.0 of Toast is planned to be a production-ready implementation,
|
30
32
|
which will be finished within 2012. Until then API/DSL changes must
|
31
|
-
be expected with each minor update.
|
33
|
+
be expected with each minor update.
|
32
34
|
|
33
35
|
Example
|
34
36
|
=======
|
@@ -47,14 +49,14 @@ and let a corresponding model class have a *acts_as_resource* annotation:
|
|
47
49
|
class Banana < ActiveRecord::Base
|
48
50
|
belongs_to :apple
|
49
51
|
has_many :coconuts
|
50
|
-
|
52
|
+
|
51
53
|
scope :less_than_100, where("number < 100")
|
52
54
|
|
53
55
|
acts_as_resource do
|
54
56
|
# exposed attributes or association names
|
55
57
|
readables :coconuts, :apple
|
56
|
-
writables :name, :number
|
57
|
-
|
58
|
+
writables :name, :number
|
59
|
+
|
58
60
|
# exposed class methods of Banana returning an Array of Banana records
|
59
61
|
collections :less_than_100, :all
|
60
62
|
end
|
@@ -130,7 +132,7 @@ With bundler from (rubygems.org)
|
|
130
132
|
|
131
133
|
the latest Git:
|
132
134
|
|
133
|
-
gem "toast", :git => "https://github.com/robokopp/toast.git"
|
135
|
+
gem "toast", :git => "https://github.com/robokopp/toast.git"
|
134
136
|
|
135
137
|
Remarks
|
136
138
|
=======
|
@@ -48,8 +48,8 @@ module Toast
|
|
48
48
|
props = {}
|
49
49
|
|
50
50
|
attr_names.each do |name|
|
51
|
-
unless self.respond_to?(name)
|
52
|
-
raise "Toast Error: Connot find instance method '#{self.class}##{name}'
|
51
|
+
unless self.respond_to?(name)
|
52
|
+
raise "Toast Error: Connot find instance method '#{self.class}##{name}'"
|
53
53
|
end
|
54
54
|
props[name] = self.send(name)
|
55
55
|
end
|
data/lib/toast/association.rb
CHANGED
@@ -88,8 +88,16 @@ module Toast
|
|
88
88
|
end
|
89
89
|
|
90
90
|
begin
|
91
|
-
|
91
|
+
reflection = @model.reflect_on_association(@assoc.to_sym)
|
92
92
|
|
93
|
+
if(@config.pass_params_to.include?(@assoc) and
|
94
|
+
reflection.options[:extend] and
|
95
|
+
reflection.options[:extend].detect{|e| e.method_defined? :create!})
|
96
|
+
|
97
|
+
record = @record.send(@assoc).create! payload, @params
|
98
|
+
else
|
99
|
+
record = @record.send(@assoc).create! payload
|
100
|
+
end
|
93
101
|
{
|
94
102
|
:json => record.represent( @associate_config_out.exposed_attributes,
|
95
103
|
@associate_config_out.exposed_associations,
|
@@ -116,9 +124,18 @@ module Toast
|
|
116
124
|
link_model = Resource.get_class_by_resource_name(link_resource_name)
|
117
125
|
link_record = link_model.find(link_id)
|
118
126
|
|
119
|
-
|
127
|
+
reflection = @model.reflect_on_association(@assoc.to_sym)
|
128
|
+
|
129
|
+
if(reflection.collection? )
|
120
130
|
# has_many, hbtm
|
121
|
-
|
131
|
+
if( @config.pass_params_to.include?(@assoc) and
|
132
|
+
reflection.options[:extend] and
|
133
|
+
reflection.options[:extend].detect{|e| e.method_defined? :<<})
|
134
|
+
|
135
|
+
@record.send(@assoc).<<(link_record,@params)
|
136
|
+
else
|
137
|
+
@record.send(@assoc) << link_record
|
138
|
+
end
|
122
139
|
else
|
123
140
|
# has_one, belongs_to
|
124
141
|
@record.send(@assoc+"=",link_record)
|
data/lib/toast/version.rb
CHANGED
metadata
CHANGED
@@ -1,95 +1,72 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: toast
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
- 1
|
10
|
-
version: 0.8.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- robokopp (Robert Anniés)
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rails
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70309039444400 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
|
-
segments:
|
30
|
-
- 3
|
31
|
-
- 1
|
32
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 3.1.0
|
34
22
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: blockenspiel
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: *70309039444400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: blockenspiel
|
27
|
+
requirement: &70309039443900 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
|
-
requirements:
|
29
|
+
requirements:
|
42
30
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 11
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
- 4
|
48
|
-
- 2
|
31
|
+
- !ruby/object:Gem::Version
|
49
32
|
version: 0.4.2
|
50
33
|
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: rack-accept-media-types
|
54
34
|
prerelease: false
|
55
|
-
|
35
|
+
version_requirements: *70309039443900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rack-accept-media-types
|
38
|
+
requirement: &70309039443440 !ruby/object:Gem::Requirement
|
56
39
|
none: false
|
57
|
-
requirements:
|
40
|
+
requirements:
|
58
41
|
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
- 9
|
64
|
-
version: "0.9"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.9'
|
65
44
|
type: :runtime
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: ffaker
|
69
45
|
prerelease: false
|
70
|
-
|
46
|
+
version_requirements: *70309039443440
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: ffaker
|
49
|
+
requirement: &70309039443060 !ruby/object:Gem::Requirement
|
71
50
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
79
55
|
type: :runtime
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70309039443060
|
58
|
+
description: ! 'Toast is an extension to Ruby on Rails that lets you expose any
|
59
|
+
|
60
|
+
ActiveRecord model as a resource according to the REST paradigm via a generic controller.
|
61
|
+
The default
|
62
|
+
|
63
|
+
representation format is JSON or can be anything'
|
85
64
|
email: robokopp@fernwerk.net
|
86
65
|
executables: []
|
87
|
-
|
88
66
|
extensions: []
|
89
|
-
|
90
|
-
extra_rdoc_files:
|
67
|
+
extra_rdoc_files:
|
91
68
|
- README.md
|
92
|
-
files:
|
69
|
+
files:
|
93
70
|
- app/controller/toast_controller.rb
|
94
71
|
- config/routes.rb
|
95
72
|
- lib/toast.rb
|
@@ -105,36 +82,26 @@ files:
|
|
105
82
|
- README.md
|
106
83
|
homepage: https://github.com/robokopp/toast
|
107
84
|
licenses: []
|
108
|
-
|
109
85
|
post_install_message:
|
110
86
|
rdoc_options: []
|
111
|
-
|
112
|
-
require_paths:
|
87
|
+
require_paths:
|
113
88
|
- lib
|
114
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
90
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
|
121
|
-
- 0
|
122
|
-
version: "0"
|
123
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
96
|
none: false
|
125
|
-
requirements:
|
126
|
-
- -
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
version: "0"
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
132
101
|
requirements: []
|
133
|
-
|
134
102
|
rubyforge_project:
|
135
|
-
rubygems_version: 1.8.
|
103
|
+
rubygems_version: 1.8.17
|
136
104
|
signing_key:
|
137
105
|
specification_version: 3
|
138
106
|
summary: Toast adds a RESTful interface to ActiveRecord models in Ruby on Rails.
|
139
107
|
test_files: []
|
140
|
-
|