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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac980b374337decc27f455542605a5aaf6da146ec1a3b96547e69f9287061b44
4
- data.tar.gz: 1df7c23ac090efebb1498bc6ecc8d9944a282edf03179fae71a88c5204c08102
3
+ metadata.gz: 3667d085d34c9dc82b81c74d86ee0d71586582b2b52072e22c0ef79b2cf12bfa
4
+ data.tar.gz: 2062f976d9bd10e73020fedeab83fcc468a14685e713fbd44e0b927e160872b7
5
5
  SHA512:
6
- metadata.gz: 40d83c52a139b9f76e7eda851cc071f4435b3a7c8d35a294e632d45a92471c34753b72c5ac0d5b0e600646ad7cce468a7f56ffbca0b39ab8f410a28fea9c1a8e
7
- data.tar.gz: 6aadec0ca9cf96a877df5e534b1be7870cee3417d2332d23410b8bb0e223af1224b6b85a0b4b5f11c319525c8f643f020e1dd98680acfaf7ad861ce622050947
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.4)
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 (6.0.1)
14
+ activesupport (7.1.3)
15
+ base64
16
+ bigdecimal
15
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
- i18n (>= 0.7, < 2)
17
- minitest (~> 5.1)
18
- tzinfo (~> 1.1)
19
- zeitwerk (~> 2.2)
20
- concurrent-ruby (1.1.5)
21
- i18n (1.7.0)
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.13.0)
26
- mocha (1.9.0)
27
- metaclass (~> 0.0.1)
28
- rake (12.3.1)
29
- ruby2ruby (2.4.4)
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.14.1)
33
- sexp_processor (~> 4.9)
34
- sexp_processor (4.13.0)
35
- thread_safe (0.3.6)
36
- tzinfo (1.2.5)
37
- thread_safe (~> 0.1)
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
- 1.17.2
58
+ 2.5.4
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'active_mappers'
3
- s.version = '1.4.6'
4
- s.date = '2020-11-10'
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
@@ -23,4 +23,4 @@ module ActiveMappers
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -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[:context]) : one(args, options[:context])
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[:context]) }
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[:context]) }
123
+ { resource_name.to_s.singularize.to_sym => one(args, options) }
119
124
  end
120
125
  end
121
126
 
122
- def self.all(collection, context = nil)
123
- collection.map { |el| one(el, context) }.compact
127
+ def self.all(collection, options = {})
128
+ collection.map { |el| one(el, options) }.compact
124
129
  end
125
130
 
126
- def self.one(resource, context = nil)
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.6
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michaël Villeneuve
8
- autorequire:
8
+ - Loïc SENCE
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
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.1.2
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: []