apple_core 1.4.1 → 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: f869f1185e23950b6ae33ba96812fe7ac8ae866c6062b754802c00436329dc22
4
- data.tar.gz: 82c0b3b4274c031d719f0c3a601e97b428be1ff11fb21a81353ec001de749fc6
3
+ metadata.gz: ec8382b41b1db19d702cdec4cf4cb8f9ce2ede593353d38badee3ac398b0964c
4
+ data.tar.gz: c5112a2ae300974165e0c26628cd6b110063af45ac7f402c6e54c3933cfba5ac
5
5
  SHA512:
6
- metadata.gz: bef1067195220d80dfd89caf6911fdd5ed4c54636fd49317d3f3affd751996b0f8eb40994914605a3dd170d5568d73b8f767ee5f93a931ad2b346f7d36e58549
7
- data.tar.gz: 154665543960907f869c49d1046a22ceda02b22d553cbb04f1e7d133fbe164f95487fbd5ee536759c9f19b463882d1363fe8957f1b190adecfad058b7950af10
6
+ metadata.gz: 2504c1d0f191c10dc8f4e2ca44b8f79c48afcaaf6051f76e3e94319dbdd1777cd4e9eac95fbb00a4150406cbf9df01d6d2bc723147b9bef95acbf5ed1d84f09b
7
+ data.tar.gz: 8916366a83a20f470fdd5ab6f28b5c02bb228f6bb2db024b38bc3ac6251785b6ff61d9784f184f315d38eb0c7f1f83148ab6beef3e612fe88cd3b9e5d986ece6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Stolen from https://github.com/rails/rails/blob/94ca3e0a571dba0fe41ca18d61634c5f3aa11209/activesupport/lib/active_support/core_ext/class/attribute.rb
5
+ # and https://github.com/rails/rails/blob/94ca3e0a571dba0fe41ca18d61634c5f3aa11209/activesupport/lib/active_support/core_ext/module/remove_method.rb
6
+
7
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
8
+ # rubocop:disable Metrics/PerceivedComplexity
9
+ # rubocop:disable Style/Send, Style/GuardClause, Metrics/BlockNesting
10
+ # rubocop:disable Style/OptionHash
11
+ module AppleCore
12
+ module Extensions
13
+ module Class
14
+ module ClassMethods
15
+ def class_attribute(method_name, options = {})
16
+ instance_reader = options.fetch(:instance_accessor, true) &&
17
+ options.fetch(:instance_reader, true)
18
+ instance_writer = options.fetch(:instance_accessor, true) &&
19
+ options.fetch(:instance_writer, true)
20
+
21
+ remove_possible_singleton_method(method_name)
22
+ define_singleton_method(method_name) { options[:default] }
23
+
24
+ ivar = "@#{method_name}"
25
+
26
+ remove_possible_singleton_method("#{method_name}=")
27
+ define_singleton_method("#{method_name}=") do |val|
28
+ singleton_class.class_eval do
29
+ remove_possible_method(method_name)
30
+ define_method(method_name) { val }
31
+ end
32
+
33
+ if singleton_class?
34
+ class_eval do
35
+ remove_possible_method(method_name)
36
+ define_method(method_name) do
37
+ if instance_variable_defined? ivar
38
+ instance_variable_get ivar
39
+ else
40
+ singleton_class.send method_name
41
+ end
42
+ end
43
+ end
44
+ end
45
+ val
46
+ end
47
+
48
+ if instance_reader
49
+ remove_possible_method method_name
50
+ define_method(method_name) do
51
+ if instance_variable_defined?(ivar)
52
+ instance_variable_get ivar
53
+ else
54
+ self.class.public_send method_name
55
+ end
56
+ end
57
+ end
58
+
59
+ if instance_writer
60
+ remove_possible_method "#{method_name}="
61
+ attr_writer method_name
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.included(base)
67
+ base.extend(ClassMethods)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ # rubocop:enable Style/OptionHash
73
+ # rubocop:enable Style/Send, Style/GuardClause, Metrics/BlockNesting
74
+ # rubocop:enable Metrics/PerceivedComplexity
75
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Stolen from https://github.com/rails/rails/blob/94ca3e0a571dba0fe41ca18d61634c5f3aa11209/activesupport/lib/active_support/core_ext/class/attribute.rb
5
+ # and https://github.com/rails/rails/blob/94ca3e0a571dba0fe41ca18d61634c5f3aa11209/activesupport/lib/active_support/core_ext/module/remove_method.rb
6
+
7
+ class Module
8
+ def remove_possible_method(method)
9
+ return unless method_defined?(method) || private_method_defined?(method)
10
+
11
+ undef_method(method)
12
+ end
13
+
14
+ # Removes the named singleton method, if it exists.
15
+ def remove_possible_singleton_method(method)
16
+ singleton_class.instance_eval do
17
+ remove_possible_method(method)
18
+ end
19
+ end
20
+
21
+ # Replaces the existing method definition, if there is one, with the passed
22
+ # block as its body.
23
+ def redefine_method(method, &block)
24
+ remove_possible_method(method)
25
+ define_method(method, &block)
26
+ end
27
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'apple_core/transforms/enumerable'
4
+
3
5
  module AppleCore
4
6
  module Refinements
5
7
  module Array
@@ -33,6 +35,14 @@ refine ::Array do
33
35
  {}
34
36
  end
35
37
  end
38
+
39
+ def deep_transform_keys(&block)
40
+ Transforms::Enumerable.deep_transform_keys(self, &block)
41
+ end
42
+
43
+ def deep_transform_values(&block)
44
+ Transforms::Enumerable.deep_transform_values(nil, self, &block)
45
+ end
36
46
  end
37
47
  end
38
48
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'apple_core/transforms/hash'
3
+ require 'apple_core/transforms/enumerable'
4
4
 
5
5
  module AppleCore
6
6
  module Refinements
@@ -17,7 +17,15 @@ refine ::Hash do
17
17
  end
18
18
 
19
19
  def deep_underscore_keys
20
- Transforms::Hash.deep_underscore_keys(self)
20
+ Transforms::Enumerable.deep_underscore_keys(self)
21
+ end
22
+
23
+ def deep_transform_keys(&block)
24
+ Transforms::Enumerable.deep_transform_keys(self, &block)
25
+ end
26
+
27
+ def deep_transform_values(&block)
28
+ Transforms::Enumerable.deep_transform_values(nil, self, &block)
21
29
  end
22
30
 
23
31
  unless method_defined?(:slice)
@@ -33,6 +33,23 @@ refine ::String do
33
33
  end
34
34
  # rubocop:enable Style/PerlBackrefs
35
35
 
36
+ def constantize
37
+ names = split('::')
38
+ names.shift if names.empty? || names.first.empty?
39
+
40
+ constant = Object
41
+
42
+ names.each do |name|
43
+ constant = if constant.const_defined?(name)
44
+ constant.const_get(name)
45
+ else
46
+ constant.const_missing(name)
47
+ end
48
+ end
49
+
50
+ constant
51
+ end
52
+
36
53
  # rubocop:disable Metrics/MethodLength
37
54
  def pluralize
38
55
  result = to_s.dup
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/refinements/string'
4
+
5
+ module AppleCore
6
+ module Transforms
7
+ class Enumerable
8
+ using ::AppleCore::Refinements::String
9
+
10
+ def self.deep_underscore_keys(other)
11
+ deep_transform_keys(other, &:underscore)
12
+ end
13
+
14
+ def self.deep_transform_keys(object, &block)
15
+ case object
16
+ when ::Hash
17
+ object.each_with_object({}) do |(key, value), result|
18
+ result[yield(key)] = deep_transform_keys(value, &block)
19
+ end
20
+ when ::Array
21
+ object.map { |e| deep_transform_keys(e, &block) }
22
+ else
23
+ object
24
+ end
25
+ end
26
+
27
+ def self.deep_transform_values(key, value, &block)
28
+ if value.is_a?(::Hash)
29
+ value.each_with_object({}) do |(k, v), memo|
30
+ memo[k] = deep_transform_values(k, v, &block)
31
+ end
32
+ elsif value.is_a?(::Array)
33
+ yield(
34
+ key,
35
+ value.map { |v| deep_transform_values(nil, v, &block) }
36
+ )
37
+ else
38
+ yield(key, value)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppleCore
4
- VERSION = '1.4.1'
4
+ VERSION = '1.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -10,28 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2NWZZXZGj+S20BzNgoK6SXrO9wt
24
+ ygKYnjP4X6ySdcuAPYyPoi/MZdZgOS+8r1VCxvLLld+Jqste8ooXrY+B1Fdxy5vQ
25
+ Br5WXCgjAgMBAAGjgZQwgZEwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
26
+ BBYEFN5ncvipiAOElX1scE7OOMsMPQgjMCsGA1UdEQQkMCKBIHJ1YnlnZW1zQGxp
27
+ dmluZ2hpZ2hvbnRoZWJsb2cuY29tMCsGA1UdEgQkMCKBIHJ1YnlnZW1zQGxpdmlu
28
+ Z2hpZ2hvbnRoZWJsb2cuY29tMA0GCSqGSIb3DQEBCwUAA4IBgQCWFC+AfDVJ8HD/
29
+ OZ6kB1knRdi9/OxnOmtdzZ0c6JRnmQl2MDMVICHsJ3+TRobSC+/7bCGu+Q2/smo6
30
+ oruQmFTxiJ6aJ0Tzo/7T3qrlfqr2ApnJfcNPQ3r6u3N0x38l7ncqA85cy3T2bV09
31
+ 1GmsuX0P117b5eHYhXzNowFK16bavxb1LBMz85f1pILKrWOB853E/eCftr5r3EX7
32
+ d+RPbPIqss99EcQtcqI1e8t/LTX4pFs+SGInFhfl1kiOhks7/Et3rYWLuSe8+/Pf
33
+ Z3/k8xnmRTv9Tx71tmcalnOPP45hePx7JE1jJr6An8XWpV7b18Mb9Y3s6a4VXvB0
34
+ Sm1kq49mzDrFMIqVF68NYWuxzGgc7BZnqKf1s4XEvxdHiipEsS5Bxj/hHr+FT4oe
35
+ eUgMp+qKjyM1NGj/222soSUpWqOE16L23vv8sWIbMIADdR8dephQ6jMovYylUmE5
36
+ KHp+JJQviSN0i4z8gVL2zloo+xZf791LiJH8Kcjpx43jhg0WdR4=
33
37
  -----END CERTIFICATE-----
34
- date: 2018-07-12 00:00:00.000000000 Z
38
+ date: 2019-01-16 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: activemodel
@@ -116,6 +120,8 @@ files:
116
120
  - lib/apple_core/active_model/errors.rb
117
121
  - lib/apple_core/active_model/validations/inclusion_validator.rb
118
122
  - lib/apple_core/active_record/base.rb
123
+ - lib/apple_core/extensions/class.rb
124
+ - lib/apple_core/extensions/module.rb
119
125
  - lib/apple_core/railtie.rb
120
126
  - lib/apple_core/refinements/array.rb
121
127
  - lib/apple_core/refinements/deep_dup.rb
@@ -123,7 +129,7 @@ files:
123
129
  - lib/apple_core/refinements/integer.rb
124
130
  - lib/apple_core/refinements/query_string.rb
125
131
  - lib/apple_core/refinements/string.rb
126
- - lib/apple_core/transforms/hash.rb
132
+ - lib/apple_core/transforms/enumerable.rb
127
133
  - lib/apple_core/version.rb
128
134
  homepage: https://example.com
129
135
  licenses:
@@ -146,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
152
  version: '0'
147
153
  requirements: []
148
154
  rubyforge_project:
149
- rubygems_version: 2.7.7
155
+ rubygems_version: 2.7.6
150
156
  signing_key:
151
157
  specification_version: 4
152
158
  summary: Non-Active Support
metadata.gz.sig CHANGED
@@ -1,3 +1 @@
1
- +
2
- ��jòz]D�|T�ʕ��^z�!�3��4w��*�����;G�h����VK�] F�Īf���,y�m���A��_Uc����[��n�|K�6=L�}<c����m̃��y�ҿߥ�:|=�/f>���(����(�S��~��'����6���ڇ��^�d�I��h<��ח�݆s��Pv�S^�-�G���
3
- ��z�x�q �/���3gDS�pZ�4�T� ��*��m��z���<Q���G��
1
+ ��˙��Ȏ�Q�ǣ�-���Tޜ�.�W2��X��*!��P���a�A;���}!���-��p{m`�O�x�㴃"��,;A����`���=#�J�w"f}r����T}�5�"^�߶�a�D�g��Lev�o�~����E�Է�jn���i?i�&���W�_��Z�+S9�`J�*�|����j$�^�KFPO��ji���~��,֨f8���
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'apple_core/refinements/string'
4
-
5
- module AppleCore
6
- module Transforms
7
- class Hash
8
- using ::AppleCore::Refinements::String
9
-
10
- def self.deep_underscore_keys(other)
11
- return other unless other.is_a? ::Hash
12
-
13
- other.each_with_object({}) do |(key, value), hash|
14
- value = case value
15
- when ::Hash
16
- deep_underscore_keys(value)
17
- when ::Array
18
- value.map do |item|
19
- deep_underscore_keys(item)
20
- end
21
- else
22
- value
23
- end
24
-
25
- hash[key.to_s.underscore] = value
26
- end
27
- end
28
- end
29
- end
30
- end