jsapi 1.1.1 → 1.2
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/json/array.rb +4 -0
- data/lib/jsapi/json/object.rb +2 -0
- data/lib/jsapi/json/value.rb +5 -0
- data/lib/jsapi/model/base.rb +37 -1
- data/lib/jsapi/model/nestable.rb +27 -1
- data/lib/jsapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40ceeb6c8774b09bfb3fbfe2bc4550444a179158b43cac27d6f9923cead5971c
|
4
|
+
data.tar.gz: f6cc387571c73b93cdcc121c1c46267424a46362f4c400dee8bd53ec2e0af561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437497757705da6bfeddab26b70ab0e4df3b7abe11f78b4433f6b5576b783f8d576c0c3b2e6612b4e941d58136e965b705e5db37176f59ee672c58bf64e5bb42
|
7
|
+
data.tar.gz: d25820eec66069cba5bb25eb2a0c1cb262835a57ec60eef94199ab247332aa296ba5228ebf0a61c1bbc80c9b350aa19cfd2339cb11188c260973f3607cd6da5f
|
data/lib/jsapi/json/array.rb
CHANGED
@@ -20,6 +20,10 @@ module Jsapi
|
|
20
20
|
"#<#{self.class.name} [#{@json_values.map(&:inspect).join(', ')}]>"
|
21
21
|
end
|
22
22
|
|
23
|
+
def serializable_value(**options) # :nodoc:
|
24
|
+
@json_values.map { |element| element.serializable_value(**options) }
|
25
|
+
end
|
26
|
+
|
23
27
|
def validate(errors) # :nodoc:
|
24
28
|
return false unless super
|
25
29
|
|
data/lib/jsapi/json/object.rb
CHANGED
data/lib/jsapi/json/value.rb
CHANGED
@@ -29,6 +29,11 @@ module Jsapi
|
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
|
+
# Returns a serializable representation of +value+.
|
33
|
+
def serializable_value(**options)
|
34
|
+
options[:jsonify_values] == true ? value.as_json : value
|
35
|
+
end
|
36
|
+
|
32
37
|
# Validates it against #schema. Returns true if it is valid, false otherwise.
|
33
38
|
# Detected errors are added to +errors+.
|
34
39
|
def validate(errors)
|
data/lib/jsapi/model/base.rb
CHANGED
@@ -25,7 +25,43 @@ module Jsapi
|
|
25
25
|
extend ActiveModel::Translation
|
26
26
|
include ActiveModel::Validations
|
27
27
|
|
28
|
-
|
28
|
+
##
|
29
|
+
# :method: []
|
30
|
+
# :call-seq: [](name)
|
31
|
+
#
|
32
|
+
# Returns the value assigned to +name+.
|
33
|
+
|
34
|
+
##
|
35
|
+
# :method: additional_attributes
|
36
|
+
#
|
37
|
+
# Returns a hash containing the additional attributes.
|
38
|
+
|
39
|
+
##
|
40
|
+
# :method: attribute?
|
41
|
+
# :call-seq: attribute?(name)
|
42
|
+
#
|
43
|
+
# Returns +true+ if +name+ is present, +false+ otherwise.
|
44
|
+
|
45
|
+
##
|
46
|
+
# :method: attributes
|
47
|
+
#
|
48
|
+
# Returns a hash containing all attributes.
|
49
|
+
|
50
|
+
##
|
51
|
+
# :method: serializable_hash
|
52
|
+
# :call-seq: serializable_hash(**options)
|
53
|
+
#
|
54
|
+
# Returns a hash containing serializable representations of all attributes.
|
55
|
+
#
|
56
|
+
# Possible options are:
|
57
|
+
#
|
58
|
+
# - +:only+ - The hash contains the given attributes only.
|
59
|
+
# - +:except+ - The hash does not contain the given attributes.
|
60
|
+
# - +:symbolize_names+ - If set to true, keys are symbols.
|
61
|
+
# - +:jsonify_values+ - If set to true, values are converted by +as_json+.
|
62
|
+
|
63
|
+
delegate :[], :additional_attributes, :attribute?, :attributes,
|
64
|
+
:serializable_hash, to: :@nested
|
29
65
|
|
30
66
|
validate :_nested_validity
|
31
67
|
|
data/lib/jsapi/model/nestable.rb
CHANGED
@@ -13,7 +13,7 @@ module Jsapi
|
|
13
13
|
raw_additional_attributes.transform_values(&:value)
|
14
14
|
end
|
15
15
|
|
16
|
-
# Returns +true+ if +name+ is present, false
|
16
|
+
# Returns +true+ if +name+ is present, +false+ otherwise.
|
17
17
|
def attribute?(name)
|
18
18
|
raw_attributes.key?(name&.to_s)
|
19
19
|
end
|
@@ -32,6 +32,32 @@ module Jsapi
|
|
32
32
|
}>"
|
33
33
|
end
|
34
34
|
|
35
|
+
# Returns a hash containing serializable representations of all attributes.
|
36
|
+
#
|
37
|
+
# Possible options are:
|
38
|
+
#
|
39
|
+
# - +:only+ - The hash contains the given attributes only.
|
40
|
+
# - +:except+ - The hash does not contain the given attributes.
|
41
|
+
# - +:symbolize_names+ - If set to true, keys are symbols.
|
42
|
+
# - +:jsonify_values+ - If set to true, values are converted by +as_json+.
|
43
|
+
def serializable_hash(**options)
|
44
|
+
options = options.dup
|
45
|
+
except = options.delete(:except)&.map(&:to_s)
|
46
|
+
only = options.delete(:only)&.map(&:to_s)
|
47
|
+
symbolize_names = options[:symbolize_names] == true
|
48
|
+
|
49
|
+
{}.tap do |hash|
|
50
|
+
[raw_attributes, raw_additional_attributes].each do |attributes|
|
51
|
+
attributes.each do |name, value|
|
52
|
+
next if except&.include?(name) || only&.exclude?(name)
|
53
|
+
|
54
|
+
name = name.to_sym if symbolize_names
|
55
|
+
hash[name] = value.serializable_value(**options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
35
61
|
private
|
36
62
|
|
37
63
|
def validate_attributes(errors)
|
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: 1.
|
4
|
+
version: '1.2'
|
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: 2025-
|
11
|
+
date: 2025-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: denis@dmgoeller.de
|