codekindly-utils 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79e5249e9ed97eff6928cca7d011ceac0a38096f
4
+ data.tar.gz: 68941b4466394d7ca8b382b5ef54790bdbddcb4b
5
+ SHA512:
6
+ metadata.gz: 9ef2549c010847f4e85f94b3ceaccc2e9f8df9b029ce8cbfaa1f9398aeeaa36176524fb9a1e422712c41d63b486ecbebe7fe0574a89b645c0abc4cb4197ccc6b
7
+ data.tar.gz: 350c87f7b7a90a55641403347e5e8ebd39d898c3bc4aabb4c0a73cb10e373f5dbe82fec8f9a3143036b5825ee8139b5021532965b0b7a4f9ed6cffc66a377ee5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ .DS_Store
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/ruby
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in codekindly-utils.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jeremy Weathers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # CodeKindly::Utils
2
+
3
+ These are small utilities that I like to have around in my projects.
4
+
5
+ There is nothing terribly unique or interesting here and there are almost
6
+ certainly better ways to do things than this. These are little snippets I've
7
+ found useful in the past and continue to use through inertia.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'codekindly-utils'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install codekindly-utils
24
+
25
+ ## Usage
26
+
27
+ I occasionally use these utilities in the main logic of an app, but usually
28
+ use them as conveniences in various rake tasks that are automated or part of my
29
+ general workflow.
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
34
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
35
+ prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`.
38
+ To release a new version, update the version number in `version.rb`, and then
39
+ run `bundle exec rake release`, which will create a git tag for the version,
40
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jlw/codekindly-utils.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codekindly-utils"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "code_kindly/utils/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codekindly-utils"
8
+ spec.version = CodeKindly::Utils::VERSION
9
+ spec.authors = ["Jeremy Weathers"]
10
+ spec.email = ["jeremy@codekindly.com"]
11
+
12
+ spec.summary = %q{These are small utilities that I like to have around in my projects.}
13
+ spec.description = %q{There is nothing terribly unique or interesting here and there are almost certainly better ways to do things than this. These are little snippets I've found useful in the past and continue to use through inertia.}
14
+ spec.homepage = "https://github.com/jlw/codekindly-utils"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,12 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class ActiveRecord
4
+ class << self
5
+ def config (name = nil)
6
+ name ||= Rails.env
7
+ YAML.load_file(::File.join(Rails.root, %w[config database.yml]))[name]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class Boolean
4
+ # modified from ActiveRecord::ConnectionAdapters::Column (4.2.9)
5
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON', 'y', 'yes']
6
+ FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'n', 'no']
7
+
8
+ class << self
9
+ def from (value)
10
+ return true if is_true?(value)
11
+ return false if is_false?(value)
12
+ nil
13
+ end
14
+
15
+ def is_false? (value)
16
+ return true if FALSE_VALUES.include?(value)
17
+ if value.respond_to?(:downcase)
18
+ return true if FALSE_VALUES.include?(value.downcase)
19
+ end
20
+ false
21
+ end
22
+
23
+ def is_true? (value)
24
+ return true if TRUE_VALUES.include?(value)
25
+ if value.respond_to?(:downcase)
26
+ return true if TRUE_VALUES.include?(value.downcase)
27
+ end
28
+ false
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class Database
4
+ class << self
5
+ def clear_scope (scope)
6
+ if 0 == scope.count
7
+ puts "Nothing to clear"
8
+ else
9
+ puts "Clearing #{scope.count} #{scope.name} records"
10
+ scope.delete_all
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class Dir
4
+ class << self
5
+ def all (path)
6
+ require 'fileutils'
7
+ return [] unless ::Dir.exist?(path)
8
+ files = ::Dir.entries(path)
9
+ files.reject!{ |f| "." == f || ".." == f || ".DS_Store" == f || ".keep" == f }
10
+ files.sort
11
+ end
12
+
13
+ def find (path)
14
+ require 'fileutils'
15
+ all(path).select { |entry| ::File.directory?("#{path}/#{entry}") }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class File
4
+ class << self
5
+ def all (path)
6
+ CodeKindly::Utils::Dir.all path
7
+ end
8
+
9
+ def choose_from_options (task, h = nil)
10
+ require "highline"
11
+ h ||= HighLine.new
12
+ dir_path = ::File.join(Rails.root, "db", "data", task.name.split(":").last)
13
+ file_opts = file_options(dir_path)
14
+ return nil if file_opts.blank?
15
+ msg = "Select an existing file:"
16
+ file_opts.each do |k,v|
17
+ msg += "\n #{k}: #{v}"
18
+ end
19
+ msg += "\n 0: None of the above"
20
+ option = h.ask(msg, Integer)
21
+ file_path = file_opts.fetch(option, nil)
22
+ if file_path.present?
23
+ file_path = ::File.join(dir_path, file_path)
24
+ end
25
+ file_path
26
+ end
27
+
28
+ def file_options (path)
29
+ require 'map'
30
+ options = Map.new
31
+ key = 0
32
+ find(path).each do |file|
33
+ options[key+=1] = file
34
+ end
35
+ options
36
+ end
37
+
38
+ def find (path)
39
+ require 'fileutils'
40
+ all(path).select { |entry| ::File.file?("#{path}/#{entry}") }
41
+ end
42
+
43
+ def trash! (file_string)
44
+ require 'open3'
45
+ stdin, stdout, stderr = Open3.popen3("ls #{file_string}")
46
+ if stdout.gets
47
+ # move to trash (or delete) existing downloaded files
48
+ # sudo gem install osx-trash (http://www.dribin.org/dave/blog/archives/2008/05/24/osx_trash/)
49
+ stdin, stdout, stderr = Open3.popen3('which trash')
50
+ trash = stdout.gets
51
+ command = case
52
+ when trash then "#{trash.strip} #{file_string}" # output of `which` has ending \n
53
+ when ::File.directory?('~/.Trash') then "mv #{file_string} ~/.Trash"
54
+ else "rm #{file_string}"
55
+ end
56
+ Kernel.system(command)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class OS
4
+ class << self
5
+ def notify (message)
6
+ require 'open3'
7
+ stdin, stdout, stderr = Open3.popen3('which terminal-notifier')
8
+ tn_path = stdout.gets
9
+ if tn_path.present?
10
+ Kernel.system("#{tn_path.chomp} -message \"#{message}\" -sound Submarine")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module CodeKindly
2
+ module Utils
3
+ class Shell
4
+ class << self
5
+ def run (command)
6
+ require 'open3'
7
+ command = command.join(" ") if command.is_a?(Array)
8
+ stdout_str, stderr_str, status = Open3.capture3(command)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module CodeKindly
2
+ module Utils
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require_relative "utils/version"
2
+
3
+ require_relative "utils/boolean"
4
+ require_relative "utils/dir"
5
+ require_relative "utils/file"
6
+ require_relative "utils/o_s"
7
+ require_relative "utils/shell"
8
+
9
+ require_relative "utils/active_record"
10
+ require_relative "utils/database"
@@ -0,0 +1 @@
1
+ require_relative "code_kindly/utils"
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codekindly-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Weathers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: There is nothing terribly unique or interesting here and there are almost
56
+ certainly better ways to do things than this. These are little snippets I've found
57
+ useful in the past and continue to use through inertia.
58
+ email:
59
+ - jeremy@codekindly.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - codekindly-utils.gemspec
73
+ - lib/code_kindly/utils.rb
74
+ - lib/code_kindly/utils/active_record.rb
75
+ - lib/code_kindly/utils/boolean.rb
76
+ - lib/code_kindly/utils/database.rb
77
+ - lib/code_kindly/utils/dir.rb
78
+ - lib/code_kindly/utils/file.rb
79
+ - lib/code_kindly/utils/o_s.rb
80
+ - lib/code_kindly/utils/shell.rb
81
+ - lib/code_kindly/utils/version.rb
82
+ - lib/codekindly-utils.rb
83
+ homepage: https://github.com/jlw/codekindly-utils
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.5.5
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: These are small utilities that I like to have around in my projects.
107
+ test_files: []