active_mappers 1.4.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +32 -22
- data/active_mappers.gemspec +3 -3
- data/lib/active_mappers/handlers/inheritance.rb +1 -1
- data/lib/active_mappers.rb +19 -9
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3667d085d34c9dc82b81c74d86ee0d71586582b2b52072e22c0ef79b2cf12bfa
|
4
|
+
data.tar.gz: 2062f976d9bd10e73020fedeab83fcc468a14685e713fbd44e0b927e160872b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91225abdb07c262dedcd047a97ea95a8ef132519591880decde3525311d9a1cba65e5f3b33542cf826dfa5ddc639b2744dfbd08dcaa4e185cddd0aaf1c80a5f6
|
7
|
+
data.tar.gz: 0dcaa09aed08f57a9026c4ac6887315c39664959573d76ca95ef81c6c7b17c7f141deb73742debcbd0a972fce9b065e8123bf0587597db59b49bca7eb14a1383
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_mappers (1.
|
4
|
+
active_mappers (1.5.0)
|
5
5
|
activesupport (>= 4.2)
|
6
6
|
method_source (~> 0.9.2)
|
7
7
|
mocha (>= 1.8.0)
|
@@ -11,31 +11,41 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activesupport (
|
14
|
+
activesupport (7.1.3)
|
15
|
+
base64
|
16
|
+
bigdecimal
|
15
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
connection_pool (>= 2.2.5)
|
19
|
+
drb
|
20
|
+
i18n (>= 1.6, < 2)
|
21
|
+
minitest (>= 5.1)
|
22
|
+
mutex_m
|
23
|
+
tzinfo (~> 2.0)
|
24
|
+
base64 (0.2.0)
|
25
|
+
bigdecimal (3.1.6)
|
26
|
+
concurrent-ruby (1.2.3)
|
27
|
+
connection_pool (2.4.1)
|
28
|
+
drb (2.2.0)
|
29
|
+
ruby2_keywords
|
30
|
+
i18n (1.14.1)
|
22
31
|
concurrent-ruby (~> 1.0)
|
23
|
-
metaclass (0.0.4)
|
24
32
|
method_source (0.9.2)
|
25
|
-
minitest (5.
|
26
|
-
mocha (1.
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
minitest (5.21.2)
|
34
|
+
mocha (2.1.0)
|
35
|
+
ruby2_keywords (>= 0.0.5)
|
36
|
+
mutex_m (0.2.0)
|
37
|
+
racc (1.7.3)
|
38
|
+
rake (13.1.0)
|
39
|
+
ruby2_keywords (0.0.5)
|
40
|
+
ruby2ruby (2.5.0)
|
30
41
|
ruby_parser (~> 3.1)
|
31
42
|
sexp_processor (~> 4.6)
|
32
|
-
ruby_parser (3.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
tzinfo (
|
37
|
-
|
38
|
-
zeitwerk (2.2.1)
|
43
|
+
ruby_parser (3.21.0)
|
44
|
+
racc (~> 1.5)
|
45
|
+
sexp_processor (~> 4.16)
|
46
|
+
sexp_processor (4.17.1)
|
47
|
+
tzinfo (2.0.6)
|
48
|
+
concurrent-ruby (~> 1.0)
|
39
49
|
|
40
50
|
PLATFORMS
|
41
51
|
ruby
|
@@ -45,4 +55,4 @@ DEPENDENCIES
|
|
45
55
|
rake
|
46
56
|
|
47
57
|
BUNDLED WITH
|
48
|
-
|
58
|
+
2.5.4
|
data/active_mappers.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'active_mappers'
|
3
|
-
s.version = '1.
|
4
|
-
s.date = '
|
3
|
+
s.version = '1.5.0'
|
4
|
+
s.date = '2024-01-26'
|
5
5
|
s.summary = 'Slick, fast view layer for you Rails API.'
|
6
6
|
s.description = 'Fast, simple, declarative way to design your API\'s view layer'
|
7
|
-
s.authors = ['Michaël Villeneuve']
|
7
|
+
s.authors = ['Michaël Villeneuve', 'Loïc SENCE']
|
8
8
|
s.homepage = 'https://github.com/fidme/active_mappers'
|
9
9
|
s.email = 'contact@michaelvilleneuve.fr'
|
10
10
|
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
data/lib/active_mappers.rb
CHANGED
@@ -14,11 +14,16 @@ require_relative 'active_mappers/key_transformer'
|
|
14
14
|
module ActiveMappers
|
15
15
|
class Base
|
16
16
|
@@renderers = {}
|
17
|
+
@@inheritance_column = {}
|
17
18
|
|
18
19
|
def self.inherited(subclass)
|
19
20
|
Handlers::Inheritance.new(subclass, self).handle
|
20
21
|
end
|
21
22
|
|
23
|
+
def self.inheritance_column(val)
|
24
|
+
@@inheritance_column[name] = val
|
25
|
+
end
|
26
|
+
|
22
27
|
def self.attributes(*params)
|
23
28
|
each do |resource|
|
24
29
|
h = {}
|
@@ -49,9 +54,9 @@ module ActiveMappers
|
|
49
54
|
else
|
50
55
|
relation_class_name = resource.class&.reflect_on_association(options[:optional_path] || key)&.class_name
|
51
56
|
raise "undefined relation : #{key.to_s}" if (mapper.nil? && relation_class_name.nil?)
|
52
|
-
KeyTransformer.resource_class_to_mapper(relation_class_name, self)
|
57
|
+
KeyTransformer.resource_class_to_mapper(relation_class_name.dup, self)
|
53
58
|
end
|
54
|
-
|
59
|
+
|
55
60
|
raise "'#{mapper_to_use.name}' should be a mapper" unless mapper_to_use.ancestors.map(&:to_s).include?("ActiveMappers::Base")
|
56
61
|
|
57
62
|
{ key => mapper_to_use.with(path.to_s.split('.').inject(resource, :try), default_options.merge(options)) }
|
@@ -87,7 +92,7 @@ module ActiveMappers
|
|
87
92
|
return evaluate_scopes(args, options) unless options[:scope].nil?
|
88
93
|
|
89
94
|
response = if options[:rootless]
|
90
|
-
args.respond_to?(:each) ? all(args, options
|
95
|
+
args.respond_to?(:each) ? all(args, options) : one(args, options)
|
91
96
|
else
|
92
97
|
render_with_root(args, options)
|
93
98
|
end
|
@@ -113,21 +118,26 @@ module ActiveMappers
|
|
113
118
|
resource_name ||= KeyTransformer.apply_on(self.name)
|
114
119
|
|
115
120
|
if args.respond_to?(:each)
|
116
|
-
{ resource_name.to_s.pluralize.to_sym => all(args, options
|
121
|
+
{ resource_name.to_s.pluralize.to_sym => all(args, options) }
|
117
122
|
else
|
118
|
-
{ resource_name.to_s.singularize.to_sym => one(args, options
|
123
|
+
{ resource_name.to_s.singularize.to_sym => one(args, options) }
|
119
124
|
end
|
120
125
|
end
|
121
126
|
|
122
|
-
def self.all(collection,
|
123
|
-
collection.map { |el| one(el,
|
127
|
+
def self.all(collection, options = {})
|
128
|
+
collection.map { |el| one(el, options) }.compact
|
124
129
|
end
|
125
130
|
|
126
|
-
def self.one(resource,
|
131
|
+
def self.one(resource, options = {})
|
127
132
|
return nil unless resource
|
133
|
+
if @@inheritance_column[name] && (mapper = KeyTransformer.resource_to_mapper(resource, self) rescue nil) && name != mapper&.name
|
134
|
+
return mapper.with(resource, default_options.merge(options))
|
135
|
+
end
|
136
|
+
|
128
137
|
return {} if @@renderers[name].nil? # Mapper is empty
|
138
|
+
|
129
139
|
renderers = @@renderers[name].map do |renderer|
|
130
|
-
renderer.call(resource, context)
|
140
|
+
renderer.call(resource, options[:context])
|
131
141
|
end.reduce(&:merge)
|
132
142
|
|
133
143
|
KeyTransformer.format_keys(renderers)
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_mappers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michaël Villeneuve
|
8
|
-
|
8
|
+
- Loïc SENCE
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -101,7 +102,7 @@ homepage: https://github.com/fidme/active_mappers
|
|
101
102
|
licenses:
|
102
103
|
- MIT
|
103
104
|
metadata: {}
|
104
|
-
post_install_message:
|
105
|
+
post_install_message:
|
105
106
|
rdoc_options: []
|
106
107
|
require_paths:
|
107
108
|
- lib
|
@@ -116,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
-
signing_key:
|
120
|
+
rubygems_version: 3.5.4
|
121
|
+
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: Slick, fast view layer for you Rails API.
|
123
124
|
test_files: []
|