shreddies 0.5.0 → 0.5.1
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/Gemfile.lock +1 -1
- data/lib/shreddies/json.rb +13 -13
- data/lib/shreddies/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: d6daee669edb85f0a632236f2eacdec946b07d9419a25ae88f6beb6bd09c4a19
|
4
|
+
data.tar.gz: f673da386a57e68668a356c8687a88a5f0ae7ec934ebab439b48d5fd2d53ef64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec6d5dc108f25b5d4f820574ae8051e5cc594b24d101de65f8145f476bf6f782db0361c4ffdacf6505b7fbb96708e5b6cd4ed7ff704ad4e3bd2d5653a86e3e49
|
7
|
+
data.tar.gz: 4c330bf894abf811866bd21ad77460cd7073ad89d5e97719bc2e2af73bf2d1255808b3487e6880d22c52f5e8a130a19d3b52b09c4ecd711abb4dcc71f52a46ca
|
data/Gemfile.lock
CHANGED
data/lib/shreddies/json.rb
CHANGED
@@ -44,11 +44,11 @@ module Shreddies
|
|
44
44
|
super(*methods, to: to, prefix: prefix, allow_nil: allow_nil, private: private)
|
45
45
|
end
|
46
46
|
|
47
|
-
attr_reader :subject, :options
|
47
|
+
attr_reader :subject, :options
|
48
48
|
|
49
|
-
def initialize(subject,
|
49
|
+
def initialize(subject, opts = {})
|
50
50
|
@subject = subject.is_a?(Hash) ? OpenStruct.new(subject) : subject
|
51
|
-
@options = { transform_keys: true }.merge(
|
51
|
+
@options = { transform_keys: true }.merge(opts)
|
52
52
|
|
53
53
|
extend_with_modules
|
54
54
|
end
|
@@ -66,17 +66,17 @@ module Shreddies
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# Filter out methods using the `only` or `except` options.
|
69
|
-
if options[:only]
|
70
|
-
options[:only] = Array(options[:only])
|
71
|
-
methods = methods.select { |x| options[:only].include? x }
|
72
|
-
elsif options[:except]
|
73
|
-
methods = methods.excluding(options[:except])
|
69
|
+
if @options[:only]
|
70
|
+
@options[:only] = Array(@options[:only])
|
71
|
+
methods = methods.select { |x| @options[:only].include? x }
|
72
|
+
elsif @options[:except]
|
73
|
+
methods = methods.excluding(@options[:except])
|
74
74
|
end
|
75
75
|
|
76
76
|
methods.map do |attr|
|
77
77
|
res = public_send(attr)
|
78
78
|
if res.is_a?(ActiveRecord::Relation) || res.is_a?(ActiveRecord::Base)
|
79
|
-
res = res.as_json(transform_keys: options[:transform_keys])
|
79
|
+
res = res.as_json(transform_keys: @options[:transform_keys])
|
80
80
|
end
|
81
81
|
|
82
82
|
output[attr] = res
|
@@ -84,7 +84,7 @@ module Shreddies
|
|
84
84
|
|
85
85
|
output = before_render(output)
|
86
86
|
|
87
|
-
return output unless options[:transform_keys]
|
87
|
+
return output unless @options[:transform_keys]
|
88
88
|
|
89
89
|
output.deep_transform_keys { |key| key.to_s.camelize :lower }
|
90
90
|
end
|
@@ -101,7 +101,7 @@ module Shreddies
|
|
101
101
|
|
102
102
|
# Extend with Collection module if it exists, and a collection is being rendered. Otherwise,
|
103
103
|
# extend with the Single module if that exists.
|
104
|
-
if options[:from_collection]
|
104
|
+
if @options[:from_collection]
|
105
105
|
(collection_mod = "#{ancestor}::Collection".safe_constantize) && extend(collection_mod)
|
106
106
|
else
|
107
107
|
(single_mod = "#{ancestor}::Single".safe_constantize) && extend(single_mod)
|
@@ -109,8 +109,8 @@ module Shreddies
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# Extend with the :module option if given.
|
112
|
-
if options[:module]
|
113
|
-
Array(options[:module]).each do |m|
|
112
|
+
if @options[:module]
|
113
|
+
Array(@options[:module]).each do |m|
|
114
114
|
extend m.is_a?(Module) ? m : "#{self.class}::#{m}".constantize
|
115
115
|
end
|
116
116
|
end
|
data/lib/shreddies/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shreddies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|