jsapi 0.7.2 → 0.7.3
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 +4 -4
- data/lib/jsapi/model/base.rb +37 -9
- data/lib/jsapi/model.rb +0 -2
- data/lib/jsapi/version.rb +1 -1
- metadata +2 -4
- data/lib/jsapi/model/attributes.rb +0 -26
- data/lib/jsapi/model/naming.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b8caebf611ba584ebd5963fefb3e7f4600f3cdda59eeda99049225f4a17fff
|
4
|
+
data.tar.gz: 94db4048e68964bc70e64068631a3ae01b9ef7434fab23976e69b6368f809d37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 144e852da54524999df466dbdf078227cae7d5e68d3155fbc3730b298072d696a39cea1c786513c34862bcb71a14b163bd202b9c203e4736598cb0fddc28813b
|
7
|
+
data.tar.gz: 9d76e40aa500597eec1a5a7dc02b794ccde643f603227455ccbcea76a6e074769c246335a1e554fa19bc6d06cf8cf36ad030147a651de58f148b3c4db5c12322
|
data/lib/jsapi/model/base.rb
CHANGED
@@ -2,14 +2,32 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Model
|
5
|
-
# The base API model
|
6
|
-
# parameters by default.
|
5
|
+
# The base API model.
|
7
6
|
class Base
|
8
|
-
extend Naming
|
9
|
-
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
# Overrides <code>ActiveModel::Naming#model_name</code> to support anonymous
|
10
|
+
# model classes.
|
11
|
+
def self.model_name
|
12
|
+
@_model_name ||= begin
|
13
|
+
# Prevent that ActiveModel::Name::new raises an error if this is an anonymous class
|
14
|
+
klass = self
|
15
|
+
klass = klass.superclass while klass.name.nil?
|
16
|
+
|
17
|
+
# Adapted from ActiveModel::Naming#model_name
|
18
|
+
namespace = klass.module_parents.detect do |n|
|
19
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
20
|
+
end
|
21
|
+
ActiveModel::Name.new(klass, namespace)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
extend ActiveModel::Translation
|
10
26
|
include ActiveModel::Validations
|
11
27
|
|
12
|
-
|
28
|
+
delegate :[], :additional_attributes, :attribute?, :attributes, to: :@nested
|
29
|
+
|
30
|
+
validate :_nested_validity
|
13
31
|
|
14
32
|
def initialize(nested)
|
15
33
|
@nested = nested
|
@@ -22,8 +40,7 @@ module Jsapi
|
|
22
40
|
)
|
23
41
|
end
|
24
42
|
|
25
|
-
# Overrides <code>ActiveModel::Validations#errors</code>
|
26
|
-
# to use Errors as error store.
|
43
|
+
# Overrides <code>ActiveModel::Validations#errors</code> to use Errors as error store.
|
27
44
|
def errors
|
28
45
|
@errors ||= Errors.new(self)
|
29
46
|
end
|
@@ -33,11 +50,22 @@ module Jsapi
|
|
33
50
|
"#{attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')}>"
|
34
51
|
end
|
35
52
|
|
53
|
+
def method_missing(*args) # :nodoc:
|
54
|
+
name = args.first.to_s
|
55
|
+
_attr_readers.key?(name) ? _attr_readers[name] : super
|
56
|
+
end
|
57
|
+
|
58
|
+
def respond_to_missing?(param1, _param2) # :nodoc:
|
59
|
+
_attr_readers.key?(param1.to_s) ? true : super
|
60
|
+
end
|
61
|
+
|
36
62
|
private
|
37
63
|
|
38
|
-
|
64
|
+
def _attr_readers
|
65
|
+
@_attr_readers ||= attributes.transform_keys(&:underscore)
|
66
|
+
end
|
39
67
|
|
40
|
-
def
|
68
|
+
def _nested_validity
|
41
69
|
@nested.validate(errors)
|
42
70
|
end
|
43
71
|
end
|
data/lib/jsapi/model.rb
CHANGED
data/lib/jsapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Göller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Jsapi can be used to read requests, produce responses and create OpenAPI
|
14
14
|
documents
|
@@ -138,11 +138,9 @@ files:
|
|
138
138
|
- lib/jsapi/meta/schema/validation/multiple_of.rb
|
139
139
|
- lib/jsapi/meta/schema/validation/pattern.rb
|
140
140
|
- lib/jsapi/model.rb
|
141
|
-
- lib/jsapi/model/attributes.rb
|
142
141
|
- lib/jsapi/model/base.rb
|
143
142
|
- lib/jsapi/model/error.rb
|
144
143
|
- lib/jsapi/model/errors.rb
|
145
|
-
- lib/jsapi/model/naming.rb
|
146
144
|
- lib/jsapi/model/nestable.rb
|
147
145
|
- lib/jsapi/model/nested_error.rb
|
148
146
|
- lib/jsapi/version.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jsapi
|
4
|
-
module Model
|
5
|
-
module Attributes
|
6
|
-
def self.included(mod)
|
7
|
-
mod.delegate :[], :additional_attributes, :attribute?, :attributes, to: :nested
|
8
|
-
end
|
9
|
-
|
10
|
-
def method_missing(*args) # :nodoc:
|
11
|
-
name = args.first.to_s
|
12
|
-
_attr_readers.key?(name) ? _attr_readers[name] : super
|
13
|
-
end
|
14
|
-
|
15
|
-
def respond_to_missing?(param1, _param2) # :nodoc:
|
16
|
-
_attr_readers.key?(param1.to_s) ? true : super
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def _attr_readers
|
22
|
-
@_attr_readers ||= attributes.transform_keys(&:underscore)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/jsapi/model/naming.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jsapi
|
4
|
-
module Model
|
5
|
-
module Naming
|
6
|
-
include ActiveModel::Naming
|
7
|
-
include ActiveModel::Translation
|
8
|
-
|
9
|
-
# Overrides <code>ActiveModel::Naming#model_name</code> to support anonymous
|
10
|
-
# model classes.
|
11
|
-
def model_name
|
12
|
-
@_model_name ||= begin
|
13
|
-
# Copied from ActiveModel::Naming#model_name
|
14
|
-
namespace = module_parents.detect do |m|
|
15
|
-
m.respond_to?(:use_relative_model_naming?) &&
|
16
|
-
m.use_relative_model_naming?
|
17
|
-
end
|
18
|
-
# Prevent that ActiveModel::Name::new raises an error if this is an anonymous class
|
19
|
-
klass = self
|
20
|
-
klass = klass.superclass while klass.name.nil?
|
21
|
-
|
22
|
-
ActiveModel::Name.new(klass, namespace)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|