codekindly-utils 0.1.1 → 0.2.0

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: 5458e324ce706e3dfc93a691aec4677600d0b8255f77d0b005cb5f6fc44fe519
4
- data.tar.gz: bb581e0244b80623bb84e267a8c85d95d6b87012a8988277613095e4c1ac2327
3
+ metadata.gz: 968bcc4dbd4b234eb3ac611b06919c2a08140de466a80b564ae4fea895a589d5
4
+ data.tar.gz: f63f93e10db2e54a5520fc2567845b0dca2c2b260349b61493cb82ab5ebf0c55
5
5
  SHA512:
6
- metadata.gz: 76b3186ba32133e45fcbe1109453d4864ea2bcfa18fb7b0082f1b47f6e662079b90b6f1be98af630aaee01ba8aef9e581e2df64929e9c7a22ef9e5ce36d3533a
7
- data.tar.gz: e9ba07b1c992cb7545b262dc036322529466fa52c9f2d32d57c739719a4759d7779e64bae7c0bb1e9bfc152fcbfc113b67ba6798a05c2c669b1330f91f4ee693
6
+ metadata.gz: c773980b2d9805eb2300b1faaa18df173480e97ebc6788f6394a9d9c33dd24da26191c53f21e92f5afa91a650c495c37eb32a8a4cf5fed630781736fec3cb62b
7
+ data.tar.gz: 41c7fb009c8534e5f3a26dca5e57084ff9bebcb325d503939a89bfa5c7599f08f245952f127731e832757aa7052ce553b209ad92c43531ca5e70d46ec1f324a2
@@ -34,15 +34,11 @@ module CodeKindly
34
34
  configs[name || default_name]
35
35
  end
36
36
 
37
- def configs # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
37
+ def configs # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
38
38
  @configs ||= ::ActiveRecord::Base.configurations
39
39
  if @configs.class.name == 'ActiveRecord::DatabaseConfigurations' # rubocop:disable Style/ClassEqualityComparison
40
40
  @configs = @configs.configs_for.each_with_object({}) do |config, hash|
41
- hash[config.env_name] = begin
42
- config.configuration_hash
43
- rescue NoMethodError
44
- config.config
45
- end
41
+ hash[config.env_name] = config&.configuration_hash || config&.config
46
42
  end
47
43
  end
48
44
  return @configs unless @configs == {}
@@ -51,7 +47,7 @@ module CodeKindly
51
47
  file = RAILS.root.join('config', 'database.yml')
52
48
  return @configs unless ::File.readable?(file)
53
49
 
54
- @configs = YAML.load(::File.read(file)) # rubocop:disable Security/YAMLLoad
50
+ @configs = YAML.load_file(file)
55
51
  end
56
52
 
57
53
  def configurations
@@ -75,7 +71,7 @@ module CodeKindly
75
71
  def application_active_record_class?(klass)
76
72
  return false unless klass < ::ActiveRecord::Base
77
73
  return false if klass.abstract_class
78
- return false if klass.name =~ /ActiveRecord::/
74
+ return false if klass.name.include?('ActiveRecord::')
79
75
  return false if Presence.blank?(klass.name)
80
76
 
81
77
  true
@@ -97,9 +93,9 @@ module CodeKindly
97
93
  def find_classes_by_connection # rubocop:disable Metrics/AbcSize
98
94
  sets = {}.with_indifferent_access
99
95
  find_classes.each do |klass|
100
- config_name = configs.keys.select do |k|
96
+ config_name = configs.keys.find do |k|
101
97
  configs[k]['database'] == klass.connection.current_database
102
- end.first
98
+ end
103
99
  config_name ||= default_name
104
100
  sets[config_name] ||= []
105
101
  sets[config_name] << klass
@@ -15,25 +15,27 @@ module CodeKindly
15
15
  def from(value)
16
16
  return true if true?(value)
17
17
  return false if false?(value)
18
+
18
19
  nil
19
20
  end
20
21
 
21
22
  def false?(value)
22
23
  return true if FALSES.include?(value)
23
- if value.respond_to?(:downcase)
24
- return true if FALSES.include?(value.downcase)
25
- end
24
+
25
+ return true if value.respond_to?(:downcase) && FALSES.include?(value.downcase)
26
+
26
27
  false
27
28
  end
28
29
 
29
30
  def true?(value)
30
31
  return true if TRUES.include?(value)
31
- if value.respond_to?(:downcase)
32
- return true if TRUES.include?(value.downcase)
33
- end
32
+
33
+ return true if value.respond_to?(:downcase) && TRUES.include?(value.downcase)
34
+
34
35
  false
35
36
  end
36
37
 
38
+ # rubocop:disable Naming/PredicateName
37
39
  def is_false?(value)
38
40
  deprecate :is_false?, :false?, :'0.1.0'
39
41
  false?(value)
@@ -43,6 +45,7 @@ module CodeKindly
43
45
  deprecate :is_true?, :true?, :'0.1.0'
44
46
  true?(value)
45
47
  end
48
+ # rubocop:enable Naming/PredicateName
46
49
  end
47
50
  end
48
51
  end
@@ -27,6 +27,7 @@ module CodeKindly
27
27
 
28
28
  def result
29
29
  return nil if blank? @std_out
30
+
30
31
  @std_out.chomp!
31
32
  blank? @std_out ? nil : @std_out
32
33
  end
@@ -8,7 +8,7 @@ module CodeKindly
8
8
 
9
9
  def deprecate(old_m, new_m = nil, version = nil)
10
10
  msg = "[DEPRECATION] `#{old_m}` is deprecated"
11
- version ? " and will be removed in version #{version}." : '.'
11
+ msg += version ? " and will be removed in version #{version}." : '.'
12
12
  msg += " Please use `#{new_m}` instead." if new_m
13
13
  warn msg
14
14
  end
@@ -9,6 +9,7 @@ module CodeKindly
9
9
  def all(path)
10
10
  require 'fileutils'
11
11
  return [] unless ::Dir.exist?(path)
12
+
12
13
  files = ::Dir.entries(path)
13
14
  files.reject! { |f| SKIP_DIRS.include? f }
14
15
  files.sort
@@ -54,7 +54,8 @@ module CodeKindly
54
54
  trash = OS.which('trash')
55
55
  if trash then "#{trash.chomp} #{file_string}"
56
56
  elsif ::File.directory?('~/.Trash') then "mv #{file_string} ~/.Trash"
57
- else "rm #{file_string}"
57
+ else
58
+ "rm #{file_string}"
58
59
  end
59
60
  end
60
61
  end
@@ -6,6 +6,7 @@ module CodeKindly
6
6
  class << self
7
7
  def notify(message)
8
8
  return if terminal_notifier.nil?
9
+
9
10
  Command.run [
10
11
  terminal_notifier,
11
12
  "-message \"#{message}\"",
@@ -20,9 +21,7 @@ module CodeKindly
20
21
  private
21
22
 
22
23
  def terminal_notifier
23
- unless instance_variable_defined? :@terminal_notifier
24
- @terminal_notifer = which('terminal-notifier')
25
- end
24
+ @terminal_notifer = which('terminal-notifier') unless instance_variable_defined? :@terminal_notifier
26
25
  @terminal_notifier
27
26
  end
28
27
  end
@@ -6,25 +6,26 @@ module CodeKindly
6
6
  module Utils
7
7
  class SQL
8
8
  class << self
9
- def method_missing(method, *args)
9
+ def method_missing(method, *)
10
10
  m_name = method.to_s
11
- return process(m_name, *args) if respond_to_missing?(m_name)
12
- select_mn = 'select_' + m_name
13
- return process(select_mn, *args) if respond_to_missing?(select_mn)
11
+ return process(m_name, *) if respond_to_missing?(m_name)
12
+
13
+ select_mn = :"select_#{m_name}"
14
+ return process(select_mn, *) if respond_to_missing?(select_mn)
15
+
14
16
  super
15
17
  end
16
18
 
17
19
  def respond_to_missing?(method, _include_all = false)
18
20
  return false unless default_connection_class
21
+
19
22
  default_connection_class.connection.respond_to?(method)
20
23
  end
21
24
 
22
25
  protected
23
26
 
24
27
  def default_connection_class
25
- @default_connection_class ||= begin
26
- CodeKindly::Utils::ActiveRecord.default_connection_class
27
- end
28
+ @default_connection_class ||= CodeKindly::Utils::ActiveRecord.default_connection_class
28
29
  end
29
30
 
30
31
  def process(method_name, query, connection_class = NilClass)
@@ -37,6 +38,7 @@ module CodeKindly
37
38
 
38
39
  def find_connection_class(query, klass)
39
40
  return query.klass if query.is_a?(::ActiveRecord::Relation)
41
+
40
42
  if klass.respond_to? :to_sym
41
43
  klass = CodeKindly::Utils::ActiveRecord.default_connection_class(klass)
42
44
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CodeKindly
4
4
  module Utils
5
- VERSION = '0.1.1'.freeze
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -3,8 +3,8 @@
3
3
  require_relative 'code_kindly/utils'
4
4
 
5
5
  if Kernel.const_defined? :CK
6
- warn '`CK` is already defined as a constant, so you will need to use' \
7
- ' the full `CodeKindly::Utils` module name in this project.'
6
+ warn '`CK` is already defined as a constant, so you will need to use ' \
7
+ 'the full `CodeKindly::Utils` module name in this project.'
8
8
  else
9
9
  CK = CodeKindly::Utils
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codekindly-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Weathers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2025-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-performance
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: sqlite3
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +193,8 @@ files:
179
193
  homepage: https://github.com/jlw/codekindly-utils
180
194
  licenses:
181
195
  - MIT
182
- metadata: {}
196
+ metadata:
197
+ rubygems_mfa_required: 'true'
183
198
  post_install_message:
184
199
  rdoc_options: []
185
200
  require_paths:
@@ -188,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
203
  requirements:
189
204
  - - ">="
190
205
  - !ruby/object:Gem::Version
191
- version: '2.2'
206
+ version: '3.2'
192
207
  required_rubygems_version: !ruby/object:Gem::Requirement
193
208
  requirements:
194
209
  - - ">="
195
210
  - !ruby/object:Gem::Version
196
211
  version: '0'
197
212
  requirements: []
198
- rubygems_version: 3.3.26
213
+ rubygems_version: 3.5.22
199
214
  signing_key:
200
215
  specification_version: 4
201
216
  summary: These are small utilities that I like to have around in my projects.