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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7084791be003f88c17be2b03597510c729b0394ff604fb2d212884b63a41ede
4
- data.tar.gz: 3b3209280042108e5e69edef03d68753984258db142367bc8e63538918cf5949
3
+ metadata.gz: d6daee669edb85f0a632236f2eacdec946b07d9419a25ae88f6beb6bd09c4a19
4
+ data.tar.gz: f673da386a57e68668a356c8687a88a5f0ae7ec934ebab439b48d5fd2d53ef64
5
5
  SHA512:
6
- metadata.gz: 71e3dcafc78e8f775ba62fdb17de776162348ccb30449425736653108b8bd2d5288adaeaa5b71b35ceb278ddf71ce2d28bea7c34f1239740e1836c382f8a3e41
7
- data.tar.gz: 3a4a854d56c8c773bd0d5ea42802688fc95779741a69d88a91718f54eca47aa16b33c883291caf66d6c9f0f71137f4de76a4cb18cecc552f04fec10c6023d30f
6
+ metadata.gz: ec6d5dc108f25b5d4f820574ae8051e5cc594b24d101de65f8145f476bf6f782db0361c4ffdacf6505b7fbb96708e5b6cd4ed7ff704ad4e3bd2d5653a86e3e49
7
+ data.tar.gz: 4c330bf894abf811866bd21ad77460cd7073ad89d5e97719bc2e2af73bf2d1255808b3487e6880d22c52f5e8a130a19d3b52b09c4ecd711abb4dcc71f52a46ca
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shreddies (0.4.0)
4
+ shreddies (0.5.0)
5
5
  activerecord (>= 5)
6
6
  railties (>= 5)
7
7
 
@@ -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, :from_collection
47
+ attr_reader :subject, :options
48
48
 
49
- def initialize(subject, options)
49
+ def initialize(subject, opts = {})
50
50
  @subject = subject.is_a?(Hash) ? OpenStruct.new(subject) : subject
51
- @options = { transform_keys: true }.merge(options)
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
@@ -1,3 +1,3 @@
1
1
  module Shreddies
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord