toast 0.8.11 → 0.8.12
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.
- checksums.yaml +7 -0
- data/README.md +4 -2
- data/lib/toast/active_record_extensions.rb +10 -5
- data/lib/toast/config_dsl.rb +49 -10
- data/lib/toast/version.rb +1 -1
- metadata +67 -81
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf0454352fbfd4570f9e2cca9b22b5a5af6a6b33
|
4
|
+
data.tar.gz: 1d65521194dce398e9f7de27f5f1f80f4596e748
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cd09d5aa85eb63cbe58161704b1ef5c5931f85820451e543619b81428d06be48919a190d0ad2076f0ec2ae4b84546941d5e3711459ada3d104175808ebd2a3e
|
7
|
+
data.tar.gz: 3e1e2ead0049b65abe1998431af105ee4e09a26f2c64dc45cb5c9850970d50d99243bc79742ed5b19510a95d9032a747e396e744a0f1077fad34219877d565a3
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://badge.fury.io/rb/toast)
|
2
|
+
|
1
3
|
Summary
|
2
4
|
=======
|
3
5
|
|
@@ -16,8 +18,8 @@ Its main features are:
|
|
16
18
|
|
17
19
|
Toast works with
|
18
20
|
|
19
|
-
* Ruby on Rails >= 3.1.0 (currently tested up to 3.2.
|
20
|
-
* Ruby 1.8.7
|
21
|
+
* Ruby on Rails >= 3.1.0 (currently tested up to 3.2.16)
|
22
|
+
* Ruby 1.8.7, 1.9.3, 2.0.0
|
21
23
|
|
22
24
|
See the [User Manual](https://github.com/robokopp/toast/wiki/User-Manual) for a detailed description.
|
23
25
|
|
@@ -8,7 +8,6 @@ module Toast
|
|
8
8
|
def acts_as_resource &block
|
9
9
|
|
10
10
|
@toast_configs ||= Array.new
|
11
|
-
|
12
11
|
@toast_configs << Toast::ConfigDSL::Base.new(self)
|
13
12
|
|
14
13
|
Blockenspiel.invoke( block, @toast_configs.last)
|
@@ -30,6 +29,11 @@ module Toast
|
|
30
29
|
tc.media_type == media_type || tc.in_collection.media_type == media_type
|
31
30
|
end || @toast_configs.first
|
32
31
|
end
|
32
|
+
|
33
|
+
def toast_resource_uri_prefix
|
34
|
+
@toast_resource_uri_prefix ||= self.to_s.pluralize.underscore
|
35
|
+
end
|
36
|
+
|
33
37
|
end
|
34
38
|
|
35
39
|
# add instance methods
|
@@ -37,7 +41,7 @@ module Toast
|
|
37
41
|
# Return the path segment of the URI of this record
|
38
42
|
def uri_path
|
39
43
|
"/" +
|
40
|
-
self.class.
|
44
|
+
self.class.toast_resource_uri_prefix + "/" +
|
41
45
|
self.id.to_s
|
42
46
|
end
|
43
47
|
|
@@ -72,9 +76,10 @@ module Toast
|
|
72
76
|
def resourceful_model_options
|
73
77
|
nil
|
74
78
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.resourceful_models
|
82
|
+
Module.constants.select{ |c| (eval c).respond_to?(:toast_config)}.sort.map{|c| c.constantize}
|
78
83
|
end
|
79
84
|
|
80
85
|
end
|
data/lib/toast/config_dsl.rb
CHANGED
@@ -9,6 +9,7 @@ module Toast
|
|
9
9
|
@model = model
|
10
10
|
@readables = []
|
11
11
|
@writables = []
|
12
|
+
@field_comments = {}
|
12
13
|
@collections = []
|
13
14
|
@singles = []
|
14
15
|
@deletable = false
|
@@ -16,6 +17,7 @@ module Toast
|
|
16
17
|
@pass_params_to = []
|
17
18
|
@in_collection = ConfigDSL::InCollection.new model, self
|
18
19
|
@media_type = "application/json"
|
20
|
+
@apidoc = {}
|
19
21
|
|
20
22
|
@model.attr_accessible []
|
21
23
|
end
|
@@ -31,7 +33,8 @@ module Toast
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def readables= arg
|
34
|
-
|
36
|
+
@field_comments.merge! ConfigDSL.get_comments(arg, 'ro')
|
37
|
+
@readables.push *ConfigDSL.normalize(arg,"readables")
|
35
38
|
end
|
36
39
|
|
37
40
|
# args: Array or :all, :except => Array
|
@@ -42,7 +45,8 @@ module Toast
|
|
42
45
|
|
43
46
|
def writables= arg
|
44
47
|
@model.attr_accessible *arg
|
45
|
-
@
|
48
|
+
@field_comments.merge! ConfigDSL.get_comments(arg, 'rw')
|
49
|
+
@writables.push *ConfigDSL.normalize(arg,"writables")
|
46
50
|
end
|
47
51
|
|
48
52
|
# args: Array or :all, :except => Array
|
@@ -68,7 +72,7 @@ module Toast
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def pass_params_to= arg
|
71
|
-
@pass_params_to.push *ConfigDSL.
|
75
|
+
@pass_params_to.push *ConfigDSL.normalize(arg,"pass_params_to")
|
72
76
|
end
|
73
77
|
|
74
78
|
def pass_params_to *arg
|
@@ -77,7 +81,7 @@ module Toast
|
|
77
81
|
end
|
78
82
|
|
79
83
|
def collections= collections=[]
|
80
|
-
@collections = ConfigDSL.
|
84
|
+
@collections = ConfigDSL.normalize(collections, "collections")
|
81
85
|
end
|
82
86
|
|
83
87
|
def collections *arg
|
@@ -86,7 +90,7 @@ module Toast
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def singles= singles=[]
|
89
|
-
@singles = ConfigDSL.
|
93
|
+
@singles = ConfigDSL.normalize(singles, "singles")
|
90
94
|
end
|
91
95
|
|
92
96
|
def singles *arg
|
@@ -102,8 +106,18 @@ module Toast
|
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
109
|
+
def apidoc arg=nil
|
110
|
+
return(@apidoc) if arg.nil?
|
111
|
+
raise "Toast Config Error (#{model.class}): apidoc argument must be a Hash." unless arg.is_a?(Hash)
|
112
|
+
@apidoc = arg
|
113
|
+
end
|
114
|
+
|
105
115
|
# non DSL methods
|
106
116
|
dsl_methods false
|
117
|
+
|
118
|
+
def field_comments
|
119
|
+
@field_comments
|
120
|
+
end
|
107
121
|
end
|
108
122
|
|
109
123
|
class InCollection
|
@@ -120,7 +134,7 @@ module Toast
|
|
120
134
|
|
121
135
|
def readables= readables
|
122
136
|
@writables = [] # forget inherited writables
|
123
|
-
@readables = ConfigDSL.
|
137
|
+
@readables = ConfigDSL.normalize(readables,"readables")
|
124
138
|
end
|
125
139
|
|
126
140
|
def readables *arg
|
@@ -158,26 +172,51 @@ module Toast
|
|
158
172
|
(@readables + @writables).uniq.select{|f| assocs.include?(f)}
|
159
173
|
end
|
160
174
|
|
161
|
-
end
|
162
|
-
|
175
|
+
end # class InCollection
|
163
176
|
|
164
177
|
# Helper
|
165
178
|
|
166
179
|
# checks if list is made of symbols and strings
|
167
180
|
# converts a single value to an Array
|
168
181
|
# converts all symbols to strings
|
169
|
-
def self.
|
182
|
+
def self.normalize list, name
|
183
|
+
# make single element list
|
184
|
+
list = [list] unless list.is_a? Array
|
185
|
+
|
186
|
+
# remove all comments
|
187
|
+
list = list.map{|x| x.is_a?(Array) ? x.first : x}
|
188
|
+
|
189
|
+
# flatten
|
170
190
|
list = [list].flatten
|
171
191
|
|
192
|
+
# check class and stringify
|
172
193
|
list.map do |x|
|
173
194
|
if (!x.is_a?(Symbol) && !x.is_a?(String))
|
174
|
-
raise "Toast Config Error: '#{name}' should be a list of Symbols
|
195
|
+
raise "Toast Config Error: '#{name}' should be a list of Symbols"
|
175
196
|
else
|
176
197
|
x.to_s
|
177
198
|
end
|
178
199
|
end
|
179
200
|
end
|
180
201
|
|
202
|
+
# fields (readables and writables) can have comments , if passed by Arrays of the form:
|
203
|
+
# [symbol, comment]
|
204
|
+
# returns a Hash of all commented or uncommented fields as:
|
205
|
+
# { FIELD_NAME => {:comment => COMMENT, :type => type } }
|
206
|
+
def self.get_comments arg, access
|
207
|
+
comments = {}
|
208
|
+
|
209
|
+
if arg.is_a? Array
|
210
|
+
arg.each do |f|
|
211
|
+
if f.is_a? Array
|
212
|
+
comments[ f.first.to_s ] = {:comment => f[1].to_s, :access => access, :type => f[2]}
|
213
|
+
else
|
214
|
+
comments[ f.to_s ] = {:comment => '[ no comment ]', :access => access, :type => nil}
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
181
218
|
|
219
|
+
comments
|
220
|
+
end
|
182
221
|
end
|
183
222
|
end
|
data/lib/toast/version.rb
CHANGED
metadata
CHANGED
@@ -1,87 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: toast
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 8
|
8
|
-
- 11
|
9
|
-
version: 0.8.11
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.12
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
6
|
+
authors:
|
7
|
+
- robokopp (Robert Anniés)
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: rails
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 3
|
29
|
-
- 1
|
30
|
-
- 0
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
31
19
|
version: 3.1.0
|
32
20
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: blockenspiel
|
36
21
|
prerelease: false
|
37
|
-
|
38
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: blockenspiel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
39
31
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
- 4
|
44
|
-
- 2
|
32
|
+
- !ruby/object:Gem::Version
|
45
33
|
version: 0.4.2
|
46
34
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rack-accept-media-types
|
50
35
|
prerelease: false
|
51
|
-
|
52
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
53
38
|
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-accept-media-types
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
59
48
|
type: :runtime
|
60
|
-
version_requirements: *id003
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: ffaker
|
63
49
|
prerelease: false
|
64
|
-
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ffaker
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
71
62
|
type: :runtime
|
72
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
73
69
|
description: |-
|
74
70
|
Toast is an extension to Ruby on Rails that lets you expose any
|
75
71
|
ActiveRecord model as a resource according to the REST paradigm via a generic controller. The default
|
76
72
|
representation format is JSON or can be anything
|
77
73
|
email: robokopp@fernwerk.net
|
78
74
|
executables: []
|
79
|
-
|
80
75
|
extensions: []
|
81
|
-
|
82
|
-
extra_rdoc_files:
|
76
|
+
extra_rdoc_files:
|
83
77
|
- README.md
|
84
|
-
files:
|
78
|
+
files:
|
85
79
|
- app/controller/toast_controller.rb
|
86
80
|
- config/routes.rb
|
87
81
|
- lib/toast.rb
|
@@ -95,35 +89,27 @@ files:
|
|
95
89
|
- lib/toast/resource.rb
|
96
90
|
- lib/toast/single.rb
|
97
91
|
- README.md
|
98
|
-
has_rdoc: true
|
99
92
|
homepage: https://github.com/robokopp/toast
|
100
93
|
licenses: []
|
101
|
-
|
94
|
+
metadata: {}
|
102
95
|
post_install_message:
|
103
96
|
rdoc_options: []
|
104
|
-
|
105
|
-
require_paths:
|
97
|
+
require_paths:
|
106
98
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
segments:
|
119
|
-
- 0
|
120
|
-
version: "0"
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
121
109
|
requirements: []
|
122
|
-
|
123
110
|
rubyforge_project:
|
124
|
-
rubygems_version:
|
111
|
+
rubygems_version: 2.0.3
|
125
112
|
signing_key:
|
126
|
-
specification_version:
|
113
|
+
specification_version: 4
|
127
114
|
summary: Toast adds a RESTful interface to ActiveRecord models in Ruby on Rails.
|
128
115
|
test_files: []
|
129
|
-
|