him 0.1.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/.github/workflows/ci.yml +40 -0
- data/.gitignore +6 -0
- data/.qlty/qlty.toml +57 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +26 -0
- data/Gemfile +2 -0
- data/LICENSE +8 -0
- data/README.md +1007 -0
- data/Rakefile +11 -0
- data/UPGRADE.md +101 -0
- data/gemfiles/Gemfile.activemodel-6.1 +6 -0
- data/gemfiles/Gemfile.activemodel-7.0 +6 -0
- data/gemfiles/Gemfile.activemodel-7.1 +6 -0
- data/gemfiles/Gemfile.activemodel-7.2 +6 -0
- data/gemfiles/Gemfile.activemodel-8.0 +6 -0
- data/him.gemspec +28 -0
- data/lib/him/api.rb +121 -0
- data/lib/him/collection.rb +21 -0
- data/lib/him/errors.rb +29 -0
- data/lib/him/json_api/model.rb +42 -0
- data/lib/him/middleware/accept_json.rb +18 -0
- data/lib/him/middleware/first_level_parse_json.rb +37 -0
- data/lib/him/middleware/json_api_parser.rb +65 -0
- data/lib/him/middleware/parse_json.rb +22 -0
- data/lib/him/middleware/second_level_parse_json.rb +37 -0
- data/lib/him/middleware.rb +12 -0
- data/lib/him/model/associations/association.rb +147 -0
- data/lib/him/model/associations/association_proxy.rb +47 -0
- data/lib/him/model/associations/belongs_to_association.rb +95 -0
- data/lib/him/model/associations/has_many_association.rb +113 -0
- data/lib/him/model/associations/has_one_association.rb +79 -0
- data/lib/him/model/associations.rb +141 -0
- data/lib/him/model/attributes.rb +337 -0
- data/lib/him/model/base.rb +33 -0
- data/lib/him/model/http.rb +113 -0
- data/lib/him/model/introspection.rb +77 -0
- data/lib/him/model/nested_attributes.rb +45 -0
- data/lib/him/model/orm.rb +306 -0
- data/lib/him/model/parse.rb +224 -0
- data/lib/him/model/paths.rb +125 -0
- data/lib/him/model/relation.rb +212 -0
- data/lib/him/model.rb +79 -0
- data/lib/him/version.rb +3 -0
- data/lib/him.rb +22 -0
- data/spec/api_spec.rb +120 -0
- data/spec/collection_spec.rb +70 -0
- data/spec/json_api/model_spec.rb +260 -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 +1010 -0
- data/spec/model/attributes_spec.rb +384 -0
- data/spec/model/callbacks_spec.rb +194 -0
- data/spec/model/dirty_spec.rb +133 -0
- data/spec/model/http_spec.rb +187 -0
- data/spec/model/introspection_spec.rb +110 -0
- data/spec/model/nested_attributes_spec.rb +135 -0
- data/spec/model/orm_spec.rb +717 -0
- data/spec/model/parse_spec.rb +619 -0
- data/spec/model/paths_spec.rb +348 -0
- data/spec/model/relation_spec.rb +255 -0
- data/spec/model/validations_spec.rb +45 -0
- data/spec/model_spec.rb +55 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/extensions/array.rb +6 -0
- data/spec/support/extensions/hash.rb +6 -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 +201 -0
data/spec/model_spec.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Him::Model do
|
|
6
|
+
before do
|
|
7
|
+
Him::API.setup url: "https://api.example.com" do |connection|
|
|
8
|
+
connection.use Him::Middleware::FirstLevelParseJSON
|
|
9
|
+
connection.adapter :test do |stub|
|
|
10
|
+
stub.get("/users/1") { [200, {}, { id: 1, name: "Tobias Fünke" }.to_json] }
|
|
11
|
+
stub.get("/users/1/comments") { [200, {}, [{ id: 4, body: "They're having a FIRESALE?" }].to_json] }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
spawn_model("Foo::User") { has_many :comments }
|
|
16
|
+
spawn_model("Foo::Comment")
|
|
17
|
+
end
|
|
18
|
+
subject { Foo::User.find(1) }
|
|
19
|
+
|
|
20
|
+
describe :has_key? do
|
|
21
|
+
it { is_expected.not_to have_key(:unknown_method_for_a_user) }
|
|
22
|
+
it { is_expected.not_to have_key(:unknown_method_for_a_user) }
|
|
23
|
+
it { is_expected.to have_key(:name) }
|
|
24
|
+
it { is_expected.to have_key(:comments) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe :serialization do
|
|
28
|
+
it "should be serialized without an error" do
|
|
29
|
+
expect { Marshal.dump(subject.comments) }.not_to raise_error
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should correctly load serialized object" do
|
|
33
|
+
serialized_comments = Marshal.load(Marshal.dump(subject.comments))
|
|
34
|
+
expect(subject.comments.size).to eq(serialized_comments.size)
|
|
35
|
+
expect(subject.comments.first.id).to eq(serialized_comments.first.id)
|
|
36
|
+
expect(subject.comments.first.body).to eq(serialized_comments.first.body)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe :[] do
|
|
41
|
+
it { is_expected.not_to have_key(:unknown_method_for_a_user) }
|
|
42
|
+
specify { expect(subject[:name]).to eq("Tobias Fünke") }
|
|
43
|
+
specify { expect(subject[:comments].first.body).to eq("They're having a FIRESALE?") }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe :dup do
|
|
47
|
+
it "does not share mutable state between original and copy" do
|
|
48
|
+
original = Foo::User.find(1)
|
|
49
|
+
copy = original.dup
|
|
50
|
+
copy.name = "Lindsay Fünke"
|
|
51
|
+
expect(original.name).to eq("Tobias Fünke")
|
|
52
|
+
expect(copy.name).to eq("Lindsay Fünke")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
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 "him"
|
|
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 Him::Testing::Macros::ModelMacros
|
|
14
|
+
config.include Him::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 Her
|
|
2
|
+
module Testing
|
|
3
|
+
module Macros
|
|
4
|
+
module ModelMacros
|
|
5
|
+
# Create a class and automatically inject Him::Model into it
|
|
6
|
+
def spawn_model(klass, options = {}, &block)
|
|
7
|
+
super_class = options[:super_class]
|
|
8
|
+
model_type = options[:type] || Him::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 Her
|
|
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,201 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: him
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dale Stevens
|
|
8
|
+
- Rémi Prévost
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2026-03-31 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rake
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '13.0'
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '13.0'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rspec
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - "~>"
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '3.5'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - "~>"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '3.5'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: activemodel
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '6.1'
|
|
49
|
+
type: :runtime
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '6.1'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: faraday
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '2.0'
|
|
63
|
+
type: :runtime
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '2.0'
|
|
70
|
+
description: Him is an ORM that maps REST resources and collections to Ruby objects,
|
|
71
|
+
designed for RESTful API-powered applications.
|
|
72
|
+
email:
|
|
73
|
+
- dale@twilightcoders.net
|
|
74
|
+
executables: []
|
|
75
|
+
extensions: []
|
|
76
|
+
extra_rdoc_files: []
|
|
77
|
+
files:
|
|
78
|
+
- ".github/workflows/ci.yml"
|
|
79
|
+
- ".gitignore"
|
|
80
|
+
- ".qlty/qlty.toml"
|
|
81
|
+
- ".rspec"
|
|
82
|
+
- ".ruby-version"
|
|
83
|
+
- ".yardopts"
|
|
84
|
+
- CONTRIBUTING.md
|
|
85
|
+
- Gemfile
|
|
86
|
+
- LICENSE
|
|
87
|
+
- README.md
|
|
88
|
+
- Rakefile
|
|
89
|
+
- UPGRADE.md
|
|
90
|
+
- gemfiles/Gemfile.activemodel-6.1
|
|
91
|
+
- gemfiles/Gemfile.activemodel-7.0
|
|
92
|
+
- gemfiles/Gemfile.activemodel-7.1
|
|
93
|
+
- gemfiles/Gemfile.activemodel-7.2
|
|
94
|
+
- gemfiles/Gemfile.activemodel-8.0
|
|
95
|
+
- him.gemspec
|
|
96
|
+
- lib/him.rb
|
|
97
|
+
- lib/him/api.rb
|
|
98
|
+
- lib/him/collection.rb
|
|
99
|
+
- lib/him/errors.rb
|
|
100
|
+
- lib/him/json_api/model.rb
|
|
101
|
+
- lib/him/middleware.rb
|
|
102
|
+
- lib/him/middleware/accept_json.rb
|
|
103
|
+
- lib/him/middleware/first_level_parse_json.rb
|
|
104
|
+
- lib/him/middleware/json_api_parser.rb
|
|
105
|
+
- lib/him/middleware/parse_json.rb
|
|
106
|
+
- lib/him/middleware/second_level_parse_json.rb
|
|
107
|
+
- lib/him/model.rb
|
|
108
|
+
- lib/him/model/associations.rb
|
|
109
|
+
- lib/him/model/associations/association.rb
|
|
110
|
+
- lib/him/model/associations/association_proxy.rb
|
|
111
|
+
- lib/him/model/associations/belongs_to_association.rb
|
|
112
|
+
- lib/him/model/associations/has_many_association.rb
|
|
113
|
+
- lib/him/model/associations/has_one_association.rb
|
|
114
|
+
- lib/him/model/attributes.rb
|
|
115
|
+
- lib/him/model/base.rb
|
|
116
|
+
- lib/him/model/http.rb
|
|
117
|
+
- lib/him/model/introspection.rb
|
|
118
|
+
- lib/him/model/nested_attributes.rb
|
|
119
|
+
- lib/him/model/orm.rb
|
|
120
|
+
- lib/him/model/parse.rb
|
|
121
|
+
- lib/him/model/paths.rb
|
|
122
|
+
- lib/him/model/relation.rb
|
|
123
|
+
- lib/him/version.rb
|
|
124
|
+
- spec/api_spec.rb
|
|
125
|
+
- spec/collection_spec.rb
|
|
126
|
+
- spec/json_api/model_spec.rb
|
|
127
|
+
- spec/middleware/accept_json_spec.rb
|
|
128
|
+
- spec/middleware/first_level_parse_json_spec.rb
|
|
129
|
+
- spec/middleware/json_api_parser_spec.rb
|
|
130
|
+
- spec/middleware/second_level_parse_json_spec.rb
|
|
131
|
+
- spec/model/associations/association_proxy_spec.rb
|
|
132
|
+
- spec/model/associations_spec.rb
|
|
133
|
+
- spec/model/attributes_spec.rb
|
|
134
|
+
- spec/model/callbacks_spec.rb
|
|
135
|
+
- spec/model/dirty_spec.rb
|
|
136
|
+
- spec/model/http_spec.rb
|
|
137
|
+
- spec/model/introspection_spec.rb
|
|
138
|
+
- spec/model/nested_attributes_spec.rb
|
|
139
|
+
- spec/model/orm_spec.rb
|
|
140
|
+
- spec/model/parse_spec.rb
|
|
141
|
+
- spec/model/paths_spec.rb
|
|
142
|
+
- spec/model/relation_spec.rb
|
|
143
|
+
- spec/model/validations_spec.rb
|
|
144
|
+
- spec/model_spec.rb
|
|
145
|
+
- spec/spec_helper.rb
|
|
146
|
+
- spec/support/extensions/array.rb
|
|
147
|
+
- spec/support/extensions/hash.rb
|
|
148
|
+
- spec/support/macros/her_macros.rb
|
|
149
|
+
- spec/support/macros/model_macros.rb
|
|
150
|
+
- spec/support/macros/request_macros.rb
|
|
151
|
+
homepage: https://github.com/TwilightCoders/him
|
|
152
|
+
licenses:
|
|
153
|
+
- MIT
|
|
154
|
+
metadata: {}
|
|
155
|
+
post_install_message:
|
|
156
|
+
rdoc_options: []
|
|
157
|
+
require_paths:
|
|
158
|
+
- lib
|
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
|
+
requirements:
|
|
161
|
+
- - ">="
|
|
162
|
+
- !ruby/object:Gem::Version
|
|
163
|
+
version: '3.1'
|
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
|
+
requirements:
|
|
166
|
+
- - ">="
|
|
167
|
+
- !ruby/object:Gem::Version
|
|
168
|
+
version: '0'
|
|
169
|
+
requirements: []
|
|
170
|
+
rubygems_version: 3.5.22
|
|
171
|
+
signing_key:
|
|
172
|
+
specification_version: 4
|
|
173
|
+
summary: An ORM that maps REST resources to Ruby objects. Forked from Her.
|
|
174
|
+
test_files:
|
|
175
|
+
- spec/api_spec.rb
|
|
176
|
+
- spec/collection_spec.rb
|
|
177
|
+
- spec/json_api/model_spec.rb
|
|
178
|
+
- spec/middleware/accept_json_spec.rb
|
|
179
|
+
- spec/middleware/first_level_parse_json_spec.rb
|
|
180
|
+
- spec/middleware/json_api_parser_spec.rb
|
|
181
|
+
- spec/middleware/second_level_parse_json_spec.rb
|
|
182
|
+
- spec/model/associations/association_proxy_spec.rb
|
|
183
|
+
- spec/model/associations_spec.rb
|
|
184
|
+
- spec/model/attributes_spec.rb
|
|
185
|
+
- spec/model/callbacks_spec.rb
|
|
186
|
+
- spec/model/dirty_spec.rb
|
|
187
|
+
- spec/model/http_spec.rb
|
|
188
|
+
- spec/model/introspection_spec.rb
|
|
189
|
+
- spec/model/nested_attributes_spec.rb
|
|
190
|
+
- spec/model/orm_spec.rb
|
|
191
|
+
- spec/model/parse_spec.rb
|
|
192
|
+
- spec/model/paths_spec.rb
|
|
193
|
+
- spec/model/relation_spec.rb
|
|
194
|
+
- spec/model/validations_spec.rb
|
|
195
|
+
- spec/model_spec.rb
|
|
196
|
+
- spec/spec_helper.rb
|
|
197
|
+
- spec/support/extensions/array.rb
|
|
198
|
+
- spec/support/extensions/hash.rb
|
|
199
|
+
- spec/support/macros/her_macros.rb
|
|
200
|
+
- spec/support/macros/model_macros.rb
|
|
201
|
+
- spec/support/macros/request_macros.rb
|