codekindly-utils 0.0.9 → 0.0.14

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: c1e0ca8f0c779cfd72c4c90a54a026563bf4558241c84210111b4d2c1a8cc064
4
- data.tar.gz: 2f38daf630fdf766564b439f692afd847c3646ae694b7b32ca7c1f7b768aa49c
3
+ metadata.gz: a63346ba5c2ae3f64f3ec02e879aeec8be27f4e6ff2b87c948239a3df2e92677
4
+ data.tar.gz: 9c085ad8982632732ab1e81460e036991438206d0c3ac750b5683a302e83549a
5
5
  SHA512:
6
- metadata.gz: 3fa0d46a81f85cde2611f2746ab0c10168c46464a52fd62a056080ba90f2330546032f3ffb3586cb2e2e399d835d5841af05fb1bb1fbf2ce8f0289802e6a8eb1
7
- data.tar.gz: d7b32548c6063a1ffe97d09f45abb2701348b5c11110fca2856044693977244e46d2845e2c68c396737330feebd9e558b16ad2a84a703a9e8badeb75e683f324
6
+ metadata.gz: ed6a912aa2056fdd19b7df73d6a695bdc4e5e2f40deba1205f47c06fb0e3ff8e256cba0dab18f5f83009f6228d047c82f1b1db47c01184d91921261a6b7c2ada
7
+ data.tar.gz: f912458c47a0d9157884a85354fe3dd67ecaa8a9c1d61bb19f8856c6a32ecefcbfc563ca77aa2dc7d54c7bb8b5e2b39bc1e5d05f9b744e8275334b1f1288c230
data/CONTRIBUTING.md CHANGED
@@ -4,13 +4,14 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jlw/co
4
4
 
5
5
  ## Setup
6
6
 
7
- `bundle install --path vendor`
7
+ `bundle install --path vendor/bundle`
8
8
 
9
9
  ## Run tests
10
10
 
11
11
  To run tests against all supported Ruby versions and all supported major dependency versions:
12
12
 
13
13
  ```Shell
14
+ ./all_rubies bundle
14
15
  ./all_rubies appraisal-install
15
16
  ./all_rubies appraisal-spec
16
17
  ```
@@ -31,5 +32,5 @@ To release a new version of the gem to RubyGems.org:
31
32
 
32
33
  ```Shell
33
34
  bundle exec rake install
34
- gem push vendor/ruby/2.5.0/cache/codekindly-utils-x.y.z.gem
35
+ gem push pkg/codekindly-utils-x.y.z.gem
35
36
  ```
@@ -34,8 +34,20 @@ module CodeKindly
34
34
  configs[name || default_name]
35
35
  end
36
36
 
37
- def configs
37
+ def configs # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38
38
  @configs ||= ::ActiveRecord::Base.configurations
39
+ if @configs.class.name == 'ActiveRecord::DatabaseConfigurations' # rubocop:disable Style/ClassEqualityComparison
40
+ @configs = @configs.configs_for.each_with_object({}) do |config, hash|
41
+ hash[config.env_name] = config.config
42
+ end
43
+ end
44
+ return @configs unless @configs == {}
45
+ return @configs unless RAILS.respond_to?(:root)
46
+
47
+ file = RAILS.root.join('config', 'database.yml')
48
+ return @configs unless ::File.readable?(file)
49
+
50
+ @configs = YAML.load(::File.read(file)) # rubocop:disable Security/YAMLLoad
39
51
  end
40
52
 
41
53
  def configurations
@@ -61,6 +73,7 @@ module CodeKindly
61
73
  return false if klass.abstract_class
62
74
  return false if klass.name =~ /ActiveRecord::/
63
75
  return false if Presence.blank?(klass.name)
76
+
64
77
  true
65
78
  rescue NoMethodError
66
79
  false
@@ -70,18 +83,14 @@ module CodeKindly
70
83
  @default_name ||= RAILS.try(:env) || configs.keys.first || 'default'
71
84
  end
72
85
 
73
- # rubocop:disable Metrics/AbcSize
74
86
  def find_classes
75
- if RAILS.try(:env).try(:development?)
76
- model_files = RAILS.root.join('app', 'models').to_s + '/**/*.rb'
77
- ::Dir.glob(model_files) { |f| require f }
78
- end
87
+ load_classes_in_development
79
88
  ObjectSpace.each_object(Class).select do |klass|
80
89
  application_active_record_class?(klass)
81
90
  end.sort_by(&:name)
82
91
  end
83
92
 
84
- def find_classes_by_connection
93
+ def find_classes_by_connection # rubocop:disable Metrics/AbcSize
85
94
  sets = {}.with_indifferent_access
86
95
  find_classes.each do |klass|
87
96
  config_name = configs.keys.select do |k|
@@ -93,7 +102,17 @@ module CodeKindly
93
102
  end
94
103
  sets
95
104
  end
96
- # rubocop:enable Metrics/AbcSize
105
+
106
+ def load_classes_in_development
107
+ return unless RAILS.try(:env).try(:development?)
108
+
109
+ ::Dir.glob(RAILS.root.join('app/models/**/*.rb').to_s) do |f|
110
+ klass = ::File.basename(f, '.rb').classify
111
+ next if Kernel.const_defined? klass
112
+
113
+ require f
114
+ end
115
+ end
97
116
  end
98
117
  end
99
118
  end
@@ -3,8 +3,6 @@
3
3
  module CodeKindly
4
4
  module Utils
5
5
  class File
6
- include Presence
7
-
8
6
  class << self
9
7
  def all(path)
10
8
  CodeKindly::Utils::Dir.all path
@@ -14,11 +12,13 @@ module CodeKindly
14
12
  require 'highline'
15
13
  h_l ||= HighLine.new
16
14
  file_opts = file_options(dir_path)
17
- return nil if blank? file_opts
18
- msg = file_opts.inject('') { |(k, v), m| m + "\n #{k}: #{v}" }
19
- option = h_l.ask("Select a file:#{msg}\n 0: None", Integer)
15
+ return nil if CodeKindly::Utils::Presence.blank? file_opts
16
+
17
+ msg = file_opts.map { |k, v| "\n #{k}: #{v}" } + ["\n 0: None"]
18
+ option = h_l.ask("Select a file:#{msg.join}", Integer)
20
19
  file_path = file_opts.fetch(option, nil)
21
20
  return if file_path.nil?
21
+
22
22
  ::File.join(dir_path, file_path)
23
23
  end
24
24
 
@@ -40,13 +40,17 @@ module CodeKindly
40
40
  # move to trash (or delete) existing downloaded files
41
41
  # sudo gem install osx-trash (http://www.dribin.org/dave/blog/archives/2008/05/24/osx_trash/)
42
42
  def trash!(file_string)
43
- Kernel.system(command_to_trash_files(file_string))
43
+ command = command_to_trash_files(file_string)
44
+ return if command.nil?
45
+
46
+ Kernel.system(command)
44
47
  end
45
48
 
46
49
  private
47
50
 
48
51
  def command_to_trash_files(file_string)
49
52
  return if Command.run("ls #{file_string}").result.nil?
53
+
50
54
  trash = OS.which('trash')
51
55
  if trash then "#{trash.chomp} #{file_string}"
52
56
  elsif ::File.directory?('~/.Trash') then "mv #{file_string} ~/.Trash"
@@ -9,7 +9,7 @@ module CodeKindly
9
9
  end
10
10
 
11
11
  def blank?(value)
12
- self.class.blank?(value)
12
+ ::CodeKindly::Utils::Presence.blank?(value)
13
13
  end
14
14
 
15
15
  def self.present?(value)
@@ -17,7 +17,7 @@ module CodeKindly
17
17
  end
18
18
 
19
19
  def present?(value)
20
- self.class.present?(value)
20
+ ::CodeKindly::Utils::Presence.present?(value)
21
21
  end
22
22
  end
23
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CodeKindly
4
4
  module Utils
5
- VERSION = '0.0.9'.freeze
5
+ VERSION = '0.0.14'.freeze
6
6
  end
7
7
  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.0.9
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Weathers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.16'
75
+ version: '2.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.16'
82
+ version: '2.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry-byebug
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -195,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubyforge_project:
199
- rubygems_version: 2.7.6
198
+ rubygems_version: 3.2.15
200
199
  signing_key:
201
200
  specification_version: 4
202
201
  summary: These are small utilities that I like to have around in my projects.