restorm 1.0.0
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/.gitignore +4 -0
- data/.rspec +1 -0
- data/.rubocop.yml +31 -0
- data/.rubocop_todo.yml +232 -0
- data/.ruby-version +1 -0
- data/.travis.yml +55 -0
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +26 -0
- data/Gemfile +10 -0
- data/HER_README.md +1065 -0
- data/LICENSE +7 -0
- data/README.md +7 -0
- data/Rakefile +11 -0
- data/UPGRADE.md +101 -0
- data/gemfiles/Gemfile.activemodel-4.2 +6 -0
- data/gemfiles/Gemfile.activemodel-5.0 +6 -0
- data/gemfiles/Gemfile.activemodel-5.1 +6 -0
- data/gemfiles/Gemfile.activemodel-5.2 +6 -0
- data/gemfiles/Gemfile.faraday-1.0 +6 -0
- data/lib/restorm/api.rb +121 -0
- data/lib/restorm/collection.rb +13 -0
- data/lib/restorm/errors.rb +29 -0
- data/lib/restorm/json_api/model.rb +42 -0
- data/lib/restorm/middleware/accept_json.rb +18 -0
- data/lib/restorm/middleware/first_level_parse_json.rb +37 -0
- data/lib/restorm/middleware/json_api_parser.rb +37 -0
- data/lib/restorm/middleware/parse_json.rb +22 -0
- data/lib/restorm/middleware/second_level_parse_json.rb +37 -0
- data/lib/restorm/middleware.rb +12 -0
- data/lib/restorm/model/associations/association.rb +128 -0
- data/lib/restorm/model/associations/association_proxy.rb +44 -0
- data/lib/restorm/model/associations/belongs_to_association.rb +95 -0
- data/lib/restorm/model/associations/has_many_association.rb +100 -0
- data/lib/restorm/model/associations/has_one_association.rb +79 -0
- data/lib/restorm/model/associations.rb +141 -0
- data/lib/restorm/model/attributes.rb +322 -0
- data/lib/restorm/model/base.rb +33 -0
- data/lib/restorm/model/deprecated_methods.rb +61 -0
- data/lib/restorm/model/http.rb +119 -0
- data/lib/restorm/model/introspection.rb +67 -0
- data/lib/restorm/model/nested_attributes.rb +45 -0
- data/lib/restorm/model/orm.rb +299 -0
- data/lib/restorm/model/parse.rb +223 -0
- data/lib/restorm/model/paths.rb +125 -0
- data/lib/restorm/model/relation.rb +209 -0
- data/lib/restorm/model.rb +75 -0
- data/lib/restorm/version.rb +3 -0
- data/lib/restorm.rb +19 -0
- data/restorm.gemspec +29 -0
- data/spec/api_spec.rb +120 -0
- data/spec/collection_spec.rb +41 -0
- data/spec/json_api/model_spec.rb +169 -0
- data/spec/middleware/accept_json_spec.rb +11 -0
- data/spec/middleware/first_level_parse_json_spec.rb +63 -0
- data/spec/middleware/json_api_parser_spec.rb +52 -0
- data/spec/middleware/second_level_parse_json_spec.rb +35 -0
- data/spec/model/associations/association_proxy_spec.rb +29 -0
- data/spec/model/associations_spec.rb +911 -0
- data/spec/model/attributes_spec.rb +354 -0
- data/spec/model/callbacks_spec.rb +176 -0
- data/spec/model/dirty_spec.rb +133 -0
- data/spec/model/http_spec.rb +201 -0
- data/spec/model/introspection_spec.rb +81 -0
- data/spec/model/nested_attributes_spec.rb +135 -0
- data/spec/model/orm_spec.rb +704 -0
- data/spec/model/parse_spec.rb +520 -0
- data/spec/model/paths_spec.rb +348 -0
- data/spec/model/relation_spec.rb +247 -0
- data/spec/model/validations_spec.rb +43 -0
- data/spec/model_spec.rb +45 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/macros/her_macros.rb +17 -0
- data/spec/support/macros/model_macros.rb +36 -0
- data/spec/support/macros/request_macros.rb +27 -0
- metadata +203 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
|
3
|
+
require "rspec"
|
4
|
+
require "restorm"
|
5
|
+
|
6
|
+
# Require everything in `spec/support`
|
7
|
+
Dir[File.expand_path("../../spec/support/**/*.rb", __FILE__)].map(&method(:require))
|
8
|
+
|
9
|
+
# Remove ActiveModel deprecation message
|
10
|
+
I18n.enforce_available_locales = false
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include Restorm::Testing::Macros::ModelMacros
|
14
|
+
config.include Restorm::Testing::Macros::RequestMacros
|
15
|
+
|
16
|
+
config.before :each do
|
17
|
+
@spawned_models = []
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after :each do
|
21
|
+
@spawned_models.each do |model|
|
22
|
+
Object.instance_eval { remove_const model } if Object.const_defined?(model)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Restorm
|
2
|
+
module Testing
|
3
|
+
module Macros
|
4
|
+
module ModelMacros
|
5
|
+
# Create a class and automatically inject Restorm::Model into it
|
6
|
+
def spawn_model(klass, options = {}, &block)
|
7
|
+
super_class = options[:super_class]
|
8
|
+
model_type = options[:type] || Restorm::Model
|
9
|
+
new_class = if super_class
|
10
|
+
Class.new(super_class)
|
11
|
+
else
|
12
|
+
Class.new
|
13
|
+
end
|
14
|
+
if klass =~ /::/
|
15
|
+
base, submodel = klass.split(/::/).map(&:to_sym)
|
16
|
+
Object.const_set(base, Module.new) unless Object.const_defined?(base)
|
17
|
+
Object.const_get(base).module_eval do
|
18
|
+
remove_const submodel if constants.map(&:to_sym).include?(submodel)
|
19
|
+
submodel = const_set(submodel, new_class)
|
20
|
+
submodel.send(:include, model_type)
|
21
|
+
submodel.class_eval(&block) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
@spawned_models << base
|
25
|
+
else
|
26
|
+
Object.instance_eval { remove_const klass } if Object.const_defined?(klass)
|
27
|
+
Object.const_set(klass, Class.new).send(:include, model_type)
|
28
|
+
Object.const_get(klass).class_eval(&block) if block_given?
|
29
|
+
|
30
|
+
@spawned_models << klass.to_sym
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Restorm
|
2
|
+
module Testing
|
3
|
+
module Macros
|
4
|
+
module RequestMacros
|
5
|
+
def ok!(body)
|
6
|
+
[200, {}, body.to_json]
|
7
|
+
end
|
8
|
+
|
9
|
+
def error!(body)
|
10
|
+
[400, {}, body.to_json]
|
11
|
+
end
|
12
|
+
|
13
|
+
def params(env)
|
14
|
+
@params ||= begin
|
15
|
+
parsed_query = Faraday::Utils.parse_nested_query(env[:body])
|
16
|
+
|
17
|
+
if parsed_query
|
18
|
+
parsed_query.with_indifferent_access.merge(env[:params])
|
19
|
+
else
|
20
|
+
env[:params].with_indifferent_access
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restorm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rémi Prévost
|
8
|
+
- Kates Gasis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.6.3
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.6.3
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 13.0.6
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 13.0.6
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.12'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.12'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activemodel
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 4.2.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.2.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: faraday
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.7.4
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.7.4
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: multi_json
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.15.0
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.15.0
|
98
|
+
description: Restorm is an ORM that maps REST resources and collections to Ruby objects
|
99
|
+
email:
|
100
|
+
- katesgasis@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- ".rubocop_todo.yml"
|
109
|
+
- ".ruby-version"
|
110
|
+
- ".travis.yml"
|
111
|
+
- ".yardopts"
|
112
|
+
- CONTRIBUTING.md
|
113
|
+
- Gemfile
|
114
|
+
- HER_README.md
|
115
|
+
- LICENSE
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- UPGRADE.md
|
119
|
+
- gemfiles/Gemfile.activemodel-4.2
|
120
|
+
- gemfiles/Gemfile.activemodel-5.0
|
121
|
+
- gemfiles/Gemfile.activemodel-5.1
|
122
|
+
- gemfiles/Gemfile.activemodel-5.2
|
123
|
+
- gemfiles/Gemfile.faraday-1.0
|
124
|
+
- lib/restorm.rb
|
125
|
+
- lib/restorm/api.rb
|
126
|
+
- lib/restorm/collection.rb
|
127
|
+
- lib/restorm/errors.rb
|
128
|
+
- lib/restorm/json_api/model.rb
|
129
|
+
- lib/restorm/middleware.rb
|
130
|
+
- lib/restorm/middleware/accept_json.rb
|
131
|
+
- lib/restorm/middleware/first_level_parse_json.rb
|
132
|
+
- lib/restorm/middleware/json_api_parser.rb
|
133
|
+
- lib/restorm/middleware/parse_json.rb
|
134
|
+
- lib/restorm/middleware/second_level_parse_json.rb
|
135
|
+
- lib/restorm/model.rb
|
136
|
+
- lib/restorm/model/associations.rb
|
137
|
+
- lib/restorm/model/associations/association.rb
|
138
|
+
- lib/restorm/model/associations/association_proxy.rb
|
139
|
+
- lib/restorm/model/associations/belongs_to_association.rb
|
140
|
+
- lib/restorm/model/associations/has_many_association.rb
|
141
|
+
- lib/restorm/model/associations/has_one_association.rb
|
142
|
+
- lib/restorm/model/attributes.rb
|
143
|
+
- lib/restorm/model/base.rb
|
144
|
+
- lib/restorm/model/deprecated_methods.rb
|
145
|
+
- lib/restorm/model/http.rb
|
146
|
+
- lib/restorm/model/introspection.rb
|
147
|
+
- lib/restorm/model/nested_attributes.rb
|
148
|
+
- lib/restorm/model/orm.rb
|
149
|
+
- lib/restorm/model/parse.rb
|
150
|
+
- lib/restorm/model/paths.rb
|
151
|
+
- lib/restorm/model/relation.rb
|
152
|
+
- lib/restorm/version.rb
|
153
|
+
- restorm.gemspec
|
154
|
+
- spec/api_spec.rb
|
155
|
+
- spec/collection_spec.rb
|
156
|
+
- spec/json_api/model_spec.rb
|
157
|
+
- spec/middleware/accept_json_spec.rb
|
158
|
+
- spec/middleware/first_level_parse_json_spec.rb
|
159
|
+
- spec/middleware/json_api_parser_spec.rb
|
160
|
+
- spec/middleware/second_level_parse_json_spec.rb
|
161
|
+
- spec/model/associations/association_proxy_spec.rb
|
162
|
+
- spec/model/associations_spec.rb
|
163
|
+
- spec/model/attributes_spec.rb
|
164
|
+
- spec/model/callbacks_spec.rb
|
165
|
+
- spec/model/dirty_spec.rb
|
166
|
+
- spec/model/http_spec.rb
|
167
|
+
- spec/model/introspection_spec.rb
|
168
|
+
- spec/model/nested_attributes_spec.rb
|
169
|
+
- spec/model/orm_spec.rb
|
170
|
+
- spec/model/parse_spec.rb
|
171
|
+
- spec/model/paths_spec.rb
|
172
|
+
- spec/model/relation_spec.rb
|
173
|
+
- spec/model/validations_spec.rb
|
174
|
+
- spec/model_spec.rb
|
175
|
+
- spec/spec_helper.rb
|
176
|
+
- spec/support/macros/her_macros.rb
|
177
|
+
- spec/support/macros/model_macros.rb
|
178
|
+
- spec/support/macros/request_macros.rb
|
179
|
+
homepage: https://github.com/kates/restorm
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubygems_version: 3.4.10
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: A simple Representational State Transfer-based Hypertext Transfer Protocol-powered
|
202
|
+
Object Relational Mapper.
|
203
|
+
test_files: []
|