active_mappers 1.4.7 → 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: d9c952cdc3025177afc55d21f7967db40c7dad0fee5209701332433978d00c65
4
- data.tar.gz: dae057bb4874202b6534ca59d7c0e11ca3765863ed27c9ddd1b83e64baa4bb41
3
+ metadata.gz: 3667d085d34c9dc82b81c74d86ee0d71586582b2b52072e22c0ef79b2cf12bfa
4
+ data.tar.gz: 2062f976d9bd10e73020fedeab83fcc468a14685e713fbd44e0b927e160872b7
5
5
  SHA512:
6
- metadata.gz: 4fae6b5c455eb0c8eb1798a94dfac64b3bcc8cc82df6761f8669e9f574fdc3efc8e51bcfd862abf9a9293601bf28e8ea2642b55e13ba4a17f4af05efde430085
7
- data.tar.gz: 339571d128963541e8ba5ee0bde89b688b17b409169e03cecdc0afc3787d9b3fe4203a91ec1de32f32a7b87dde75b3d9d3079965934c8383df27f5aaa3b77a13
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.7'
4
- s.date = '2020-11-12'
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 = {}
@@ -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.7
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-12 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: []