apple_core 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70827ddf4d17f95a357f56339f76f80514488080c1f850517bbf77b5d2efb85b
4
+ data.tar.gz: 4043617e5c945c39bd6ea96ed12fa77b809d5d3887084d68402e0a583675ddeb
5
+ SHA512:
6
+ metadata.gz: 53a64ab985ed782fddeb8f844bb64211dcffb18f76d5a651888182a6861e0ba580cd58240fd00cf03f72abaaa0006808a5f466140dca92e92e3f0ebd2f94b29a
7
+ data.tar.gz: 6e52047122c226e8aa6af352373f97339447e261c012527ca3fb1ff3df302a686e0238e68936df42926d7f9b2f4488a1fec65eb015f27f22ae8db802c27caebc
checksums.yaml.gz.sig ADDED
Binary file
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2018 Grand Design
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Apple Core
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'apple_core'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install apple_core
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/refinements/string'
4
+
5
+ module AppleCore
6
+ module ActionController
7
+ module ResourceNaming
8
+ using ::AppleCore::Refinements::String
9
+
10
+ CONTROLLER_RESOURCE_NAME_PATTERN = /
11
+ \A # Beginning of String
12
+ (?:
13
+ (?<modules> # Full Modules
14
+ (?: # Match Root Module (Optional)
15
+ (?<root_module>
16
+ [^\:]+ # The Module Name
17
+ (?=\:\:) # Which Must Be Followed By '::'
18
+ )
19
+ (?:\:\:)? # Up Through the '::' But Don't
20
+ # Capture If It's The Sole Module
21
+ )?
22
+ (?<submodules> # Match Submodule List (Optional)
23
+ ( # There May Be Zero or More of These
24
+ [^\:]+ # The Module Name
25
+ \:\: # Up Through the '::'
26
+ )*?
27
+ (?<last_submodule> # The Final Submodule (Optional)
28
+ [^\:]+ # The Module Name
29
+ (?=\:\:) # Which Must Be Followed By '::'
30
+ )?
31
+ )?
32
+ )
33
+ \:\: # Required Final Separator
34
+ )?
35
+ (?<controller_name>
36
+ (?<resource_name>\w+?) # Base Resource Name
37
+ (?:Index|Indicies)? # Optional Index Suffix
38
+ )
39
+ Controller # Literal 'Controller'
40
+ \z # End of String
41
+ /x
42
+
43
+ def plural_underscored_base_resource_name
44
+ @plural_underscored_base_resource_name ||= plural_resource_base_class_name
45
+ .underscore
46
+ .downcase
47
+ end
48
+
49
+ def singular_underscored_base_resource_name
50
+ @singular_underscored_base_resource_name ||= singular_resource_base_class_name
51
+ .underscore
52
+ .downcase
53
+ end
54
+
55
+ def singular_resource_base_class_name
56
+ @singular_resource_base_class_name ||= plural_resource_base_class_name
57
+ .singularize
58
+ end
59
+
60
+ def plural_resource_base_class_name
61
+ @plural_resource_base_class_name ||= resource_name
62
+ .pluralize
63
+ end
64
+
65
+ def name_components
66
+ name.match(CONTROLLER_RESOURCE_NAME_PATTERN).named_captures
67
+ end
68
+
69
+ def resource_name
70
+ name[CONTROLLER_RESOURCE_NAME_PATTERN, 'resource_name']
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveModel
4
+ class Errors
5
+ def to_s
6
+ full_messages.to_sentence
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveModel
4
+ module Validations
5
+ class InclusionValidator
6
+ def validate_each(record, attribute, value)
7
+ delimiter = options[:in]
8
+ exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
9
+
10
+ valid = if value.respond_to? :all?
11
+ value.all? { |v| exclusions.include? v }
12
+ else
13
+ exclusions.public_send(inclusion_method(exclusions), value)
14
+ end
15
+
16
+ return if valid
17
+
18
+ record.errors.add(attribute,
19
+ :inclusion,
20
+ options.except(:in).merge!(value: value))
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ class Base
5
+ def to_h
6
+ attributes.symbolize_keys
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppleCore
4
+ module Refinements
5
+ module Array
6
+ refine ::Array do
7
+ def delete!(default = nil, &block)
8
+ index_of_item = index(&block)
9
+
10
+ return default unless index_of_item.present?
11
+
12
+ delete_at index_of_item
13
+ end
14
+
15
+ def compact_blank!
16
+ delete_if(&:blank?)
17
+ end
18
+
19
+ def deep_strip!
20
+ each_with_index do |value, index|
21
+ if value.respond_to?(:strip)
22
+ self[index] = value.strip
23
+ elsif value.respond_to?(:deep_strip!)
24
+ self[index] = value.deep_strip!
25
+ end
26
+ end
27
+ end
28
+
29
+ def extract_options
30
+ if last.is_a?(::Hash) && last.instance_of?(::Hash)
31
+ last
32
+ else
33
+ {}
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/transforms/hash'
4
+
5
+ module AppleCore
6
+ module Refinements
7
+ module Hash
8
+ refine ::Hash do
9
+ def deep_strip!
10
+ each do |key, value|
11
+ if value.respond_to?(:strip)
12
+ self[key] = value.strip
13
+ elsif value.respond_to?(:deep_strip!)
14
+ self[key] = value.deep_strip!
15
+ end
16
+ end
17
+ end
18
+
19
+ def deep_underscore_keys
20
+ Transforms::Hash.deep_underscore_keys(self)
21
+ end
22
+
23
+ def symbolize_keys
24
+ result = {}
25
+
26
+ each_key do |key|
27
+ result[key.to_sym] = self[key]
28
+ end
29
+
30
+ result
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppleCore
4
+ module Refinements
5
+ module Integer
6
+ refine ::Integer do
7
+ def to_strict_i
8
+ to_i
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppleCore
4
+ module Refinements
5
+ module String
6
+ refine ::String do
7
+ def only_digits?
8
+ match(/^\d+$/)
9
+ end
10
+
11
+ def to_strict_i(base = 10)
12
+ only_digits? ? to_i(base) : nil
13
+ end
14
+
15
+ unless defined?(ActiveSupport::Inflector)
16
+ # rubocop:disable Style/PerlBackrefs
17
+ def camelize(uppercase_first_letter = true)
18
+ string = if uppercase_first_letter
19
+ sub(/^[a-z\d]*/, &:capitalize)
20
+ else
21
+ downcase
22
+ end
23
+
24
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
25
+ "#{$1}#{$2.capitalize}"
26
+ end
27
+
28
+ string.gsub!('/', '::')
29
+
30
+ string
31
+ end
32
+ # rubocop:enable Style/PerlBackrefs
33
+
34
+ # rubocop:disable Metrics/MethodLength
35
+ def pluralize
36
+ result = to_s.dup
37
+
38
+ inflections = {
39
+ 'person' => 'people',
40
+ 'man' => 'men',
41
+ 'child' => 'children',
42
+ 'sex' => 'sexes',
43
+ 'move' => 'moves',
44
+ 'zombie' => 'zombies',
45
+ /(quiz)$/i => '\1zes',
46
+ /^(oxen)$/i => '\1',
47
+ /^(ox)$/i => '\1en',
48
+ /^(m|l)ice$/i => '\1ice',
49
+ /^(m|l)ouse$/i => '\1ice',
50
+ /(matr|vert|ind)(?:ix|ex)$/i => '\1ices',
51
+ /(x|ch|ss|sh)$/i => '\1es',
52
+ /([^aeiouy]|qu)y$/i => '\1ies',
53
+ /(hive)$/i => '\1s',
54
+ /(?:([^f])fe|([lr])f)$/i => '\1\2ves',
55
+ /sis$/i => 'ses',
56
+ /([ti])a$/i => '\1a',
57
+ /([ti])um$/i => '\1a',
58
+ /(buffal|tomat)o$/i => '\1oes',
59
+ /(bu)s$/i => '\1ses',
60
+ /(alias|status)$/i => '\1es',
61
+ /(octop|vir)i$/i => '\1i',
62
+ /(octop|vir)us$/i => '\1i',
63
+ /^(ax|test)is$/i => '\1es',
64
+ /s$/i => 's',
65
+ /$/ => 's',
66
+ }
67
+
68
+ inflections.each do |(rule, replacement)|
69
+ break if result.sub!(rule, replacement)
70
+ end
71
+
72
+ result
73
+ end
74
+ # rubocop:enable Metrics/MethodLength
75
+
76
+ # rubocop:disable Metrics/MethodLength, Layout/AlignHash
77
+ def singularize
78
+ result = to_s.dup
79
+
80
+ inflections = {
81
+ /(database)s$/i => '\1',
82
+ /(quiz)zes$/i => '\1',
83
+ /(matr)ices$/i => '\1ix',
84
+ /(vert|ind)ices$/i => '\1ex',
85
+ /^(ox)en/i => '\1',
86
+ /(alias|status)(es)?$/i => '\1',
87
+ /(octop|vir)(us|i)$/i => '\1us',
88
+ /^(a)x[ie]s$/i => '\1xis',
89
+ /(cris|test)(is|es)$/i => '\1is',
90
+ /(shoe)s$/i => '\1',
91
+ /(o)es$/i => '\1',
92
+ /(bus)(es)?$/i => '\1',
93
+ /^(m|l)ice$/i => '\1ouse',
94
+ /(x|ch|ss|sh)es$/i => '\1',
95
+ /(m)ovies$/i => '\1ovie',
96
+ /(s)eries$/i => '\1eries',
97
+ /([^aeiouy]|qu)ies$/i => '\1y',
98
+ /([lr])ves$/i => '\1f',
99
+ /(tive)s$/i => '\1',
100
+ /(hive)s$/i => '\1',
101
+ /([^f])ves$/i => '\1fe',
102
+ /(^analy)(sis|ses)$/i => '\1sis',
103
+ /
104
+ (
105
+ (a)naly |
106
+ (b)a |
107
+ (d)iagno |
108
+ (p)arenthe |
109
+ (p)rogno |
110
+ (s)ynop |
111
+ (t)he
112
+ )
113
+ (sis|ses)
114
+ $
115
+ /xi => '\1sis',
116
+ /([ti])a$/i => '\1um',
117
+ /(n)ews$/i => '\1ews',
118
+ /(ss)$/i => '\1',
119
+ /s$/i => '',
120
+ }
121
+
122
+ inflections.each do |(rule, replacement)|
123
+ break if result.sub!(rule, replacement)
124
+ end
125
+
126
+ result
127
+ end
128
+ # rubocop:enable Metrics/MethodLength, Layout/AlignHash
129
+
130
+ def underscore
131
+ word = gsub('::', '/')
132
+
133
+ word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) do
134
+ "#{Regexp.last_match(1)}#{Regexp.last_match(1) && ''}"
135
+ end
136
+
137
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
138
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
139
+ word.tr!('-', '_')
140
+ word.downcase!
141
+
142
+ word
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppleCore
4
+ VERSION = '1.0.1'
5
+ end
data/lib/apple_core.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/version'
4
+ require 'apple_core/active_record/base'
5
+ require 'apple_core/active_model/validations/inclusion_validator'
6
+
7
+ module AppleCore
8
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apple_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thegranddesign
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDqjCCApKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBNMREwDwYDVQQDDAhydWJ5
14
+ Z2VtczEjMCEGCgmSJomT8ixkARkWE2xpdmluZ2hpZ2hvbnRoZWJsb2cxEzARBgoJ
15
+ kiaJk/IsZAEZFgNjb20wHhcNMTcwODAyMjI1OTM1WhcNMTgwODAyMjI1OTM1WjBN
16
+ MREwDwYDV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gjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
+ iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
+ -----END CERTIFICATE-----
34
+ date: 2018-04-27 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: activemodel
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '4.2'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '4.2'
56
+ - !ruby/object:Gem::Dependency
57
+ name: activerecord
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '6.0'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '4.2'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '6.0'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.7'
90
+ - !ruby/object:Gem::Dependency
91
+ name: rspectacular
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.6'
104
+ description: To the CORE!
105
+ email:
106
+ - rubygems@livinghighontheblog.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - LICENSE.txt
112
+ - README.md
113
+ - lib/apple_core.rb
114
+ - lib/apple_core/action_controller/resource_naming.rb
115
+ - lib/apple_core/active_model/errors.rb
116
+ - lib/apple_core/active_model/validations/inclusion_validator.rb
117
+ - lib/apple_core/active_record/base.rb
118
+ - lib/apple_core/refinements/array.rb
119
+ - lib/apple_core/refinements/hash.rb
120
+ - lib/apple_core/refinements/integer.rb
121
+ - lib/apple_core/refinements/string.rb
122
+ - lib/apple_core/transforms/hash.rb
123
+ - lib/apple_core/version.rb
124
+ homepage: https://example.com
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.6
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Non-Active Support
149
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���& ����0憗��OZ?pɥ��/��q���� Z-��3@�l�uMi�BW���hT�o;��J���ר�Ϡ�mo�a �L��T3����N �����v�sPnd�)��Ǜ�����Fv�U��VsFV����P�‹�U��.Ş ��nP�x{"��>��fz_�1};����[���(v�(����,�����,0�p\Ў�ֺj!�Zp��E�ޅč�/*� VH�Er.
2
+ a�{���~K�1�׃�lT��C0�>%�d%!