k_util 0.0.3
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 +7 -0
- data/.github/workflows/main.yml +31 -0
- data/.gitignore +50 -0
- data/.rspec +3 -0
- data/.rubocop.yml +82 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +25 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +33 -0
- data/STORIES.md +46 -0
- data/USAGE.md +19 -0
- data/bin/console +16 -0
- data/bin/k +36 -0
- data/bin/kgitsync +76 -0
- data/bin/khotfix +244 -0
- data/bin/setup +11 -0
- data/hooks/pre-commit +87 -0
- data/hooks/update-version +33 -0
- data/k_util.gemspec +42 -0
- data/lib/k_util.rb +10 -0
- data/lib/k_util/data_helper.rb +64 -0
- data/lib/k_util/file_helper.rb +29 -0
- data/lib/k_util/version.rb +5 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c24b82f602689a2bc8c2b88781c49bfb8f7a3fec655259a2fef5dc1a07c19da5
|
4
|
+
data.tar.gz: 1c919acdee3df2c1191fea1285cd7a9aac5167e2a9f87b4393c85e6f884bac48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12ffdc1399c84b23bfbf30a16e3f1c7a219efe2d73ead337f2c52efb607a73bf1dbba72915a07105e577ca6da1bdf696cf52916b892faca5289631a970422226
|
7
|
+
data.tar.gz: 97c12df77317c8ced436caa47fbf84915641d889ce1653540876b8d978ed6ad56403d628989a7ba77d74e8eadc20a206c7c473845166b63517c4e8cfd65c7912
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
2
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
3
|
+
name: Ruby
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master ]
|
8
|
+
pull_request:
|
9
|
+
branches: [ master ]
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
20
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: 2.7.1
|
24
|
+
- name: Install dependencies
|
25
|
+
run: |
|
26
|
+
gem install bundler -v 2.2.5
|
27
|
+
bundle install
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rspec
|
30
|
+
- name: Run rubocop
|
31
|
+
run: bundle exec rubocop
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Move this into a KLUE SATELITE DOCUMENT
|
2
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
3
|
+
#
|
4
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
5
|
+
# or operating system, you probably want to add a global ignore instead:
|
6
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
7
|
+
#
|
8
|
+
# The Octocat has a Gist containing some good rules to add to this file.
|
9
|
+
# https://gist.github.com/octocat/9257657
|
10
|
+
|
11
|
+
# Ignore Klue Setup.sh
|
12
|
+
/bin/runonce/
|
13
|
+
k_util.yml
|
14
|
+
|
15
|
+
/_/
|
16
|
+
/.bundle/
|
17
|
+
/.history/
|
18
|
+
/.yardoc
|
19
|
+
/_yardoc/
|
20
|
+
/coverage/
|
21
|
+
/log/
|
22
|
+
!/log/.keep
|
23
|
+
/doc/
|
24
|
+
/pkg/
|
25
|
+
/spec/reports/
|
26
|
+
/tmp/
|
27
|
+
!/tmp/.keep
|
28
|
+
*.bundle
|
29
|
+
*.so
|
30
|
+
*.o
|
31
|
+
*.a
|
32
|
+
mkmf.log
|
33
|
+
|
34
|
+
# Ruby Version
|
35
|
+
.ruby-version
|
36
|
+
|
37
|
+
# Environment File
|
38
|
+
.env
|
39
|
+
|
40
|
+
# Gems should not use a Gemfile.lock
|
41
|
+
Gemfile.lock
|
42
|
+
|
43
|
+
# RubyGem definitions
|
44
|
+
*.gem
|
45
|
+
|
46
|
+
# rspec failure tracking
|
47
|
+
.rspec_status
|
48
|
+
|
49
|
+
# ByeBug history
|
50
|
+
.byebug_history
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require: rubocop-rake
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
DisplayCopNames: true
|
5
|
+
ExtraDetails: true
|
6
|
+
NewCops: enable
|
7
|
+
Exclude:
|
8
|
+
- "_/**/*"
|
9
|
+
- "spec/samples/**/*"
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Exclude:
|
13
|
+
- "**/spec/**/*"
|
14
|
+
- "*.gemspec"
|
15
|
+
IgnoredMethods:
|
16
|
+
- configure
|
17
|
+
- context
|
18
|
+
- define
|
19
|
+
- describe
|
20
|
+
- draw
|
21
|
+
- factory
|
22
|
+
- feature
|
23
|
+
- guard
|
24
|
+
- included
|
25
|
+
- it
|
26
|
+
- let
|
27
|
+
- let!
|
28
|
+
- scenario
|
29
|
+
- setup
|
30
|
+
- shared_context
|
31
|
+
- shared_examples
|
32
|
+
- shared_examples_for
|
33
|
+
- transaction
|
34
|
+
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Max: 25
|
37
|
+
|
38
|
+
Layout/LineLength:
|
39
|
+
Max: 200
|
40
|
+
# Ignores annotate output
|
41
|
+
IgnoredPatterns: ['\A# \*\*']
|
42
|
+
IgnoreCopDirectives: true
|
43
|
+
|
44
|
+
Lint/UnusedMethodArgument:
|
45
|
+
AllowUnusedKeywordArguments: true
|
46
|
+
|
47
|
+
Style/BlockComments:
|
48
|
+
Enabled: false
|
49
|
+
Include:
|
50
|
+
- "**/spec/*"
|
51
|
+
|
52
|
+
# My Preferences - Start
|
53
|
+
Metrics/ClassLength:
|
54
|
+
Enabled: false
|
55
|
+
Metrics/ModuleLength:
|
56
|
+
Exclude:
|
57
|
+
- "**/spec/**/*"
|
58
|
+
Naming/MemoizedInstanceVariableName:
|
59
|
+
Enabled: false
|
60
|
+
Naming/VariableNumber:
|
61
|
+
Exclude:
|
62
|
+
- "**/spec/**/*"
|
63
|
+
Style/EmptyMethod:
|
64
|
+
Exclude:
|
65
|
+
- "**/spec/**/*"
|
66
|
+
Metrics/ParameterLists:
|
67
|
+
Exclude:
|
68
|
+
- "**/spec/**/*"
|
69
|
+
Layout/EmptyLineBetweenDefs:
|
70
|
+
Exclude:
|
71
|
+
- "**/spec/**/*"
|
72
|
+
|
73
|
+
Lint/AmbiguousBlockAssociation:
|
74
|
+
Exclude:
|
75
|
+
- "**/spec/**/*"
|
76
|
+
|
77
|
+
Style/AccessorGrouping:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Layout/SpaceBeforeComma:
|
81
|
+
Enabled: false
|
82
|
+
# My Preferences - End
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
- Using welcoming and inclusive language
|
18
|
+
- Being respectful of differing viewpoints and experiences
|
19
|
+
- Gracefully accepting constructive criticism
|
20
|
+
- Focusing on what is best for the community
|
21
|
+
- Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
- Public or private harassment
|
29
|
+
- Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at david.cruwys@bugcrowd.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in handlebars_helpers.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# group :development do
|
9
|
+
# # Currently conflicts with GitHub actions and so I remove it on push
|
10
|
+
# # pry on steroids
|
11
|
+
# gem 'jazz_fingers'
|
12
|
+
# gem 'pry-coolline', github: 'owst/pry-coolline', branch: 'support_new_pry_config_api'
|
13
|
+
# end
|
14
|
+
|
15
|
+
group :development, :test do
|
16
|
+
gem 'guard-bundler'
|
17
|
+
gem 'guard-rspec'
|
18
|
+
gem 'guard-rubocop'
|
19
|
+
gem 'rake', '~> 12.0'
|
20
|
+
gem 'rake-compiler', require: false
|
21
|
+
gem 'rspec', '~> 3.0'
|
22
|
+
gem 'rubocop'
|
23
|
+
gem 'rubocop-rake', require: false
|
24
|
+
gem 'rubocop-rspec', require: false
|
25
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :bundler, cmd: 'bundle install' do
|
4
|
+
watch('Gemfile')
|
5
|
+
watch('k_util.gemspec')
|
6
|
+
end
|
7
|
+
|
8
|
+
group :green_pass_then_cop, halt_on_fail: true do
|
9
|
+
guard :rspec, cmd: 'bundle exec rspec -f doc' do
|
10
|
+
require 'guard/rspec/dsl'
|
11
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
12
|
+
|
13
|
+
# RSpec files
|
14
|
+
rspec = dsl.rspec
|
15
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
16
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
17
|
+
watch(rspec.spec_files)
|
18
|
+
|
19
|
+
# Ruby files
|
20
|
+
ruby = dsl.ruby
|
21
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
22
|
+
watch(%r{^lib/k_util/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
23
|
+
watch(%r{^lib/k_util/commands/(.+)\.rb$}) { |m| "spec/unit/commands/#{m[1]}_spec.rb" }
|
24
|
+
end
|
25
|
+
|
26
|
+
guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
|
27
|
+
watch(/{.+\.rb$/)
|
28
|
+
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
29
|
+
end
|
30
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 David Cruwys
|
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,91 @@
|
|
1
|
+
# K Util
|
2
|
+
|
3
|
+
> KUtil provides simple utility methods
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'k_util'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
gem install k_util
|
23
|
+
```
|
24
|
+
|
25
|
+
## Stories
|
26
|
+
|
27
|
+
### Main Story
|
28
|
+
|
29
|
+
As a Developer, I need simple utility helpers, to solve cross cutting issues
|
30
|
+
|
31
|
+
See all [stories](./STORIES.md)
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
See all [usage examples](./USAGE.md)
|
36
|
+
|
37
|
+
### Basic Example
|
38
|
+
|
39
|
+
#### Basic example
|
40
|
+
|
41
|
+
Description for a basic example to be featured in the main README.MD file
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class SomeRuby; end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
Checkout the repo
|
50
|
+
|
51
|
+
```bash
|
52
|
+
git clone klueless-io/k_util
|
53
|
+
```
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
56
|
+
|
57
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
```bash
|
60
|
+
bin/console
|
61
|
+
|
62
|
+
Aaa::Bbb::Program.execute()
|
63
|
+
# => ""
|
64
|
+
```
|
65
|
+
|
66
|
+
`k_util` is setup with Guard, run `guard`, this will watch development file changes and run tests automatically, if successful, it will then run rubocop for style quality.
|
67
|
+
|
68
|
+
To release a new version, update the version number in `version.rb`, build the gem and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
```bash
|
71
|
+
gem build
|
72
|
+
gem push rspec-usecases-?.?.??.gem
|
73
|
+
# or push the latest gem
|
74
|
+
ls *.gem | sort -r | head -1 | xargs gem push
|
75
|
+
```
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/klueless-io/k_util. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
84
|
+
|
85
|
+
## Code of Conduct
|
86
|
+
|
87
|
+
Everyone interacting in the K Util project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/klueless-io/k_util/blob/master/CODE_OF_CONDUCT.md).
|
88
|
+
|
89
|
+
## Copyright
|
90
|
+
|
91
|
+
Copyright (c) David Cruwys. See [MIT License](LICENSE.txt) for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# source: https://stephenagrice.medium.com/making-a-command-line-ruby-gem-write-build-and-push-aec24c6c49eb
|
4
|
+
|
5
|
+
GEM_NAME = 'k_util'
|
6
|
+
|
7
|
+
require 'bundler/gem_tasks'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
require 'k_util/version'
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
|
13
|
+
require 'rake/extensiontask'
|
14
|
+
|
15
|
+
desc 'Compile all the extensions'
|
16
|
+
task build: :compile
|
17
|
+
|
18
|
+
Rake::ExtensionTask.new('k_util') do |ext|
|
19
|
+
ext.lib_dir = 'lib/k_util'
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Publish the gem to RubyGems.org'
|
23
|
+
task :publish do
|
24
|
+
system 'gem build'
|
25
|
+
system "gem push #{GEM_NAME}-#{KUtil::VERSION}.gem"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Remove old *.gem files'
|
29
|
+
task :clean do
|
30
|
+
system 'rm *.gem'
|
31
|
+
end
|
32
|
+
|
33
|
+
task default: %i[clobber compile spec]
|
data/STORIES.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# K Util
|
2
|
+
|
3
|
+
> KUtil provides simple utility methods
|
4
|
+
|
5
|
+
As a Developer, I need simple utility helpers, to solve cross cutting issues
|
6
|
+
|
7
|
+
## Development radar
|
8
|
+
|
9
|
+
### Stories next on list
|
10
|
+
|
11
|
+
As a Developer, I can DO_SOMETHING, so that I QUALITY_OF_LIFE
|
12
|
+
|
13
|
+
- Subtask
|
14
|
+
|
15
|
+
### Tasks next on list
|
16
|
+
|
17
|
+
Setup RubyGems and RubyDoc
|
18
|
+
|
19
|
+
- Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_util)
|
20
|
+
- Attach documentation to [rubydoc.info](https://rubydoc.info/github/to-do-/k_util/master)
|
21
|
+
|
22
|
+
Setup GitHub Action (test and lint)
|
23
|
+
|
24
|
+
- Setup Rspec action
|
25
|
+
- Setup RuboCop action
|
26
|
+
|
27
|
+
## Stories and tasks
|
28
|
+
|
29
|
+
### Tasks - completed
|
30
|
+
|
31
|
+
Setup project management, requirement and SCRUM documents
|
32
|
+
|
33
|
+
- Setup readme file
|
34
|
+
- Setup user stories and tasks
|
35
|
+
- Setup a project backlog
|
36
|
+
- Setup an examples/usage document
|
37
|
+
|
38
|
+
Setup new Ruby GEM
|
39
|
+
|
40
|
+
- Build out a standard GEM structure
|
41
|
+
- Add automated semantic versioning
|
42
|
+
- Add Rspec unit testing framework
|
43
|
+
- Add RuboCop linting
|
44
|
+
- Add Guard for automatic watch and test
|
45
|
+
- Add GitFlow support
|
46
|
+
- Add GitHub Repository
|
data/USAGE.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# K Util
|
2
|
+
|
3
|
+
> KUtil provides simple utility methods
|
4
|
+
|
5
|
+
As a Developer, I need simple utility helpers, to solve cross cutting issues
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Sample Classes
|
10
|
+
|
11
|
+
#### Simple example
|
12
|
+
|
13
|
+
Description for a simple example that shows up in the USAGE.MD
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class SomeRuby
|
17
|
+
def initialize; end
|
18
|
+
end
|
19
|
+
```
|
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'k_util'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require 'pry'
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
IRB.start(__FILE__)
|
data/bin/k
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# NOTE: you may need change file permissions
|
5
|
+
# chmod +x bin/k
|
6
|
+
|
7
|
+
help = %(
|
8
|
+
----------------------------------------------------------------------
|
9
|
+
Klue Scripts - Help
|
10
|
+
----------------------------------------------------------------------
|
11
|
+
k - This Help File
|
12
|
+
|
13
|
+
khotfix - Create Hot Fix
|
14
|
+
Hot fixes are created in GIT and versioned correctly.
|
15
|
+
The patch # will increment by 1.
|
16
|
+
e.g. v0.1.1 will become v0.1.2
|
17
|
+
The version.rb file will also store the current version.
|
18
|
+
usage:
|
19
|
+
khotfix 'name of my cool hotfix'
|
20
|
+
|
21
|
+
kgitsync - Synchronize the master and development git repositories
|
22
|
+
Pulls latest code, pushes current changes
|
23
|
+
usage:
|
24
|
+
kgitsync
|
25
|
+
|
26
|
+
----------------------------------------------------------------------
|
27
|
+
Rake Tasks
|
28
|
+
----------------------------------------------------------------------
|
29
|
+
|
30
|
+
rails db:seed - load seed data
|
31
|
+
|
32
|
+
rails db:seed sample=true - load sample data, useful in developer environments
|
33
|
+
|
34
|
+
rails db:seed reset=true - reset database
|
35
|
+
)
|
36
|
+
puts help
|
data/bin/kgitsync
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
#NOTE: you may need change file permissions
|
4
|
+
# chmod +x bin/kgitsync
|
5
|
+
|
6
|
+
# Set up colour support, if we have it
|
7
|
+
# Are stdout and stderr both connected to a terminal
|
8
|
+
# If not then don't set colours
|
9
|
+
if [ -t 1 -a -t 2 ]
|
10
|
+
then
|
11
|
+
if tput -V >/dev/null 2>&1
|
12
|
+
then
|
13
|
+
C_RED=`tput setaf 1`
|
14
|
+
C_GREEN=`tput setaf 2`
|
15
|
+
C_BROWN=`tput setaf 3`
|
16
|
+
C_BLUE=`tput setaf 4`
|
17
|
+
C_RESET=`tput sgr0`
|
18
|
+
fi
|
19
|
+
fi
|
20
|
+
|
21
|
+
|
22
|
+
exit_error ()
|
23
|
+
{
|
24
|
+
# dont display if string is zero length
|
25
|
+
[ -z "$1" ] || echo "${C_RED}Error: ${C_BROWN} $1 ${C_RESET}"
|
26
|
+
exit 1
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
# make sure we are in a git tree
|
31
|
+
[ "`git rev-parse --is-inside-work-tree`" = "true" ] || exit_error "NOT a git repository"
|
32
|
+
echo "Repository check OK"
|
33
|
+
|
34
|
+
CURRENT_BRANCH=`git branch | awk '/^\*/{print $2}'`
|
35
|
+
|
36
|
+
# check that we are on develop or master
|
37
|
+
#[ "${CURRENT_BRANCH}" = "master" -o "${CURRENT_BRANCH}" = "develop" ] || exit_error "You MUST be on either the master or development branch"
|
38
|
+
#echo "Branch check OK"
|
39
|
+
|
40
|
+
# check that the current branch is clean
|
41
|
+
[ -z "`git status --porcelain`" ] || exit_error "Working copy has uncommitted changes"
|
42
|
+
echo "Working copy is clean OK"
|
43
|
+
|
44
|
+
# fetch from origin
|
45
|
+
git fetch origin || exit_error "Failed to fetch from origin"
|
46
|
+
|
47
|
+
######################
|
48
|
+
# Do develop
|
49
|
+
######################
|
50
|
+
git checkout develop || exit_error "Failed to checkout develop branch"
|
51
|
+
echo "Switched to develop"
|
52
|
+
git merge origin/develop || exit_error "Failed to merge develop from origin"
|
53
|
+
echo "Develop branch upto date"
|
54
|
+
git push || exit_error "Failed to push develop to origin"
|
55
|
+
echo "Develop pushed to origin"
|
56
|
+
|
57
|
+
######################
|
58
|
+
# Do master
|
59
|
+
######################
|
60
|
+
git checkout master || exit_error "Failed to checkout master branch"
|
61
|
+
echo "Switched to master"
|
62
|
+
git merge origin/master || exit_error "Failed to merge master from origin"
|
63
|
+
echo "Master branch upto date"
|
64
|
+
git push || exit_error "Failed to push master to origin"
|
65
|
+
echo "Master pushed to origin"
|
66
|
+
|
67
|
+
######################
|
68
|
+
# Do tags
|
69
|
+
######################
|
70
|
+
git push --tags || exit_error "Failed to push tags to origin"
|
71
|
+
echo "Tags pushed to origin"
|
72
|
+
|
73
|
+
# return to the current branch
|
74
|
+
git checkout ${CURRENT_BRANCH} || exit_error "Failed to return to your origional branch ${CURRENT_BRANCH}"
|
75
|
+
|
76
|
+
echo "${C_GREEN}Done. you are on ${CURRENT_BRANCH}${C_RESET}"
|
data/bin/khotfix
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
#NOTE: you may need change file permissions
|
4
|
+
# chmod +x bin/khotfix
|
5
|
+
|
6
|
+
# Create a Versioned HotFix in Git and update the VERSION #
|
7
|
+
# USAGE
|
8
|
+
#
|
9
|
+
# ./bin/khotfix.sh 'my brand new hot fix'
|
10
|
+
|
11
|
+
# HELPERS
|
12
|
+
clear
|
13
|
+
|
14
|
+
l_heading ()
|
15
|
+
{
|
16
|
+
heading=$1
|
17
|
+
|
18
|
+
echo "======================================================================"
|
19
|
+
echo "${heading}"
|
20
|
+
echo "======================================================================"
|
21
|
+
}
|
22
|
+
|
23
|
+
l_line ()
|
24
|
+
{
|
25
|
+
echo "----------------------------------------------------------------------"
|
26
|
+
}
|
27
|
+
|
28
|
+
l_title ()
|
29
|
+
{
|
30
|
+
title=$1
|
31
|
+
|
32
|
+
l_line
|
33
|
+
echo "${title}"
|
34
|
+
l_line
|
35
|
+
}
|
36
|
+
|
37
|
+
l ()
|
38
|
+
{
|
39
|
+
title=$1
|
40
|
+
|
41
|
+
echo "${title}"
|
42
|
+
}
|
43
|
+
|
44
|
+
lkv ()
|
45
|
+
{
|
46
|
+
title=$1
|
47
|
+
value=$2
|
48
|
+
|
49
|
+
printf "%-25s : %s\n" "$title" "$value"
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
# expect 1 argument
|
54
|
+
MESSAGE=$1
|
55
|
+
|
56
|
+
l_heading "Make Hotfix - '${MESSAGE}'"
|
57
|
+
|
58
|
+
|
59
|
+
# This environment var will prevent git from asking for merge messages
|
60
|
+
export GIT_MERGE_AUTOEDIT=no
|
61
|
+
|
62
|
+
# Set up colour support, if we have it
|
63
|
+
# Are stdout and stderr both connected to a terminal, If not then don't set colours
|
64
|
+
if [ -t 1 -a -t 2 ]
|
65
|
+
then
|
66
|
+
if tput -V >/dev/null 2>&1
|
67
|
+
then
|
68
|
+
C_RED=`tput setaf 1`
|
69
|
+
C_GREEN=`tput setaf 2`
|
70
|
+
C_BROWN=`tput setaf 3`
|
71
|
+
C_BLUE=`tput setaf 4`
|
72
|
+
C_RESET=`tput sgr0`
|
73
|
+
fi
|
74
|
+
fi
|
75
|
+
|
76
|
+
|
77
|
+
exit_error ()
|
78
|
+
{
|
79
|
+
# dont display if string is zero length
|
80
|
+
[ -z "$1" ] || echo "${C_RED}Error: ${C_BROWN} $1 ${C_RESET}"
|
81
|
+
exit 1
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
# check arguments
|
86
|
+
[ ! -z "${MESSAGE}" ] || exit_error "You must pass a message when making a hotfix"
|
87
|
+
|
88
|
+
# make sure we are in a git tree
|
89
|
+
[ "`git rev-parse --is-inside-work-tree`" = "true" ] || exit_error "NOT a git repository"
|
90
|
+
l "Repository check OK"
|
91
|
+
|
92
|
+
CURRENT_BRANCH=`git branch | awk '/^\*/{print $2}'`
|
93
|
+
|
94
|
+
lkv "CURRENT_BRANCH" "${CURRENT_BRANCH}"
|
95
|
+
|
96
|
+
# check that we are on develop or master
|
97
|
+
[ "${CURRENT_BRANCH}" = "master" -o "${CURRENT_BRANCH}" = "develop" ] || exit_error "You MUST be on either the master or development branch"
|
98
|
+
l "OK: Branch"
|
99
|
+
|
100
|
+
# check that the current branch is NOT clean (we need changes to make a hotfix)
|
101
|
+
[ ! -z "`git status --porcelain`" ] || exit_error "Working copy is clean - no hotfix"
|
102
|
+
l "OK: Working copy has hotfix ready"
|
103
|
+
|
104
|
+
# fetch from origin
|
105
|
+
git fetch origin || exit_error "Failed to fetch from origin"
|
106
|
+
l "OK: Fsetch from origin"
|
107
|
+
|
108
|
+
# get the current directory that this script is in.
|
109
|
+
# we assume that the other scripts are in the same directory
|
110
|
+
SYNC_SCRIPT=kgitsync
|
111
|
+
SCRIPT_DIR=`dirname $0`
|
112
|
+
|
113
|
+
# ----------------------------------------------------------------------
|
114
|
+
# GET VERSION NUMBER
|
115
|
+
# ----------------------------------------------------------------------
|
116
|
+
|
117
|
+
l_title 'GET VERSION NUMBER'
|
118
|
+
|
119
|
+
# Get the last tag version
|
120
|
+
VERSION=`git tag | sort -V | tail -1`
|
121
|
+
lkv "CURENT VERSION" "${VERSION}"
|
122
|
+
|
123
|
+
# NOTE, if you don't have a TAG then you might need to manually do
|
124
|
+
# git flow hotfix start v0.01.001
|
125
|
+
# git flow hotfix finish v0.01.001
|
126
|
+
|
127
|
+
# Verify its format
|
128
|
+
[[ "`git tag | sort -V | tail -1`" =~ ^v[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,3}$ ]] || exit_error "Bad version format, version=${VERSION}"
|
129
|
+
# extract the version components
|
130
|
+
IFS=. read MAJOR_VERSION MINOR_VERSION PATCH_VERSION <<< "${VERSION}"
|
131
|
+
|
132
|
+
# inc the patch version. note: force base 10 as leading 0 makes bash think this is octal
|
133
|
+
PATCH_VERSION=$((10#${PATCH_VERSION} + 1))
|
134
|
+
lkv 'Patch #' "${PATCH_VERSION}"
|
135
|
+
|
136
|
+
# assemble the new version
|
137
|
+
NEW_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
|
138
|
+
lkv "NEW VERSION" "${NEW_VERSION}"
|
139
|
+
|
140
|
+
./hooks/update-version "${NEW_VERSION}" || exit_error "could not update version.rb you may need to run [chmod +x hooks/update-version]"
|
141
|
+
|
142
|
+
l_line
|
143
|
+
l 'git add .'
|
144
|
+
git add .
|
145
|
+
|
146
|
+
l 'git status'
|
147
|
+
l_line
|
148
|
+
git status
|
149
|
+
|
150
|
+
# ----------------------------------------------------------------------
|
151
|
+
# Before doing anything, add the files and then run the commit hook
|
152
|
+
# Then stash any changes - working directory will be clean after this
|
153
|
+
# The commit hook is where we can check for any debugging code that has
|
154
|
+
# gone into the code and abort the commit
|
155
|
+
# ----------------------------------------------------------------------
|
156
|
+
|
157
|
+
l 'check for debugging code'
|
158
|
+
./hooks/pre-commit || exit_error "remove debugging code from the commit - then run again"
|
159
|
+
|
160
|
+
l "Stash changes to [git_make_hotfix: ${MESSAGE}]"
|
161
|
+
|
162
|
+
git stash save "git_make_hotfix: ${MESSAGE}"
|
163
|
+
|
164
|
+
l "OK: Stashed"
|
165
|
+
|
166
|
+
l_title 'Master/Develop Branches'
|
167
|
+
# ----------------------------------------------------------------------
|
168
|
+
# update develop
|
169
|
+
# ----------------------------------------------------------------------
|
170
|
+
|
171
|
+
lkv "Develop" "Synchronized"
|
172
|
+
git checkout develop || exit_error "Failed to checkout develop branch"
|
173
|
+
lkv "Develop" "Switched"
|
174
|
+
git merge origin/develop || exit_error "Failed to merge develop from origin"
|
175
|
+
lkv "Develop" "Merged and upto date"
|
176
|
+
|
177
|
+
# ----------------------------------------------------------------------
|
178
|
+
# update master
|
179
|
+
# ----------------------------------------------------------------------
|
180
|
+
|
181
|
+
lkv "Master" "Synchronized"
|
182
|
+
git checkout master || exit_error "Failed to checkout master branch"
|
183
|
+
lkv "Master" "Switched"
|
184
|
+
git merge origin/master || exit_error "Failed to merge master from origin"
|
185
|
+
lkv "Master" "Merged and upto date"
|
186
|
+
|
187
|
+
# ----------------------------------------------------------------------
|
188
|
+
# start the hotfix
|
189
|
+
# ----------------------------------------------------------------------
|
190
|
+
|
191
|
+
l_title 'Hotfix'
|
192
|
+
|
193
|
+
lkv "Version" "${NEW_VERSION}"
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
lkv "git flow hotfix start" "${NEW_VERSION}"
|
198
|
+
|
199
|
+
git flow hotfix start "${NEW_VERSION}" || exit_error "Failed to start hotfix ${NEW_VERSION}"
|
200
|
+
|
201
|
+
HOTFIX_BRANCH="hotfix/${NEW_VERSION}"
|
202
|
+
|
203
|
+
lkv "started" "${HOTFIX_BRANCH}"
|
204
|
+
|
205
|
+
# ----------------------------------------------------------------------
|
206
|
+
# commit the stashed changes
|
207
|
+
# ----------------------------------------------------------------------
|
208
|
+
|
209
|
+
lkv "git stash" "pop"
|
210
|
+
|
211
|
+
git stash pop || exit_error "Failed to pop the stash into the hotfix"
|
212
|
+
|
213
|
+
lkv "git commit" "${MESSAGE}"
|
214
|
+
|
215
|
+
git commit -a -m"${MESSAGE}" || exit_error "Failed to commit the stash to ${HOTFIX_BRANCH}"
|
216
|
+
|
217
|
+
lkv "git commit succesful" "${HOTFIX_BRANCH}"
|
218
|
+
|
219
|
+
# ----------------------------------------------------------------------
|
220
|
+
# close the hotfix
|
221
|
+
# ----------------------------------------------------------------------
|
222
|
+
|
223
|
+
lkv "git flow hotfix finish" "${NEW_VERSION}"
|
224
|
+
|
225
|
+
git flow hotfix finish "${NEW_VERSION}" -m"${MESSAGE}" || exit_error "Failed to close ${HOTFIX_BRANCH}"
|
226
|
+
|
227
|
+
lkv "finished" "${HOTFIX_BRANCH}"
|
228
|
+
|
229
|
+
# closing the hotfix leaves you on the development branch
|
230
|
+
# return to the master ???? or should we stay on development
|
231
|
+
|
232
|
+
lkv "git checkout" "master"
|
233
|
+
|
234
|
+
git checkout master || exit_error "Failed to return to master branch"
|
235
|
+
|
236
|
+
# ----------------------------------------------------------------------
|
237
|
+
# now push the changes
|
238
|
+
# ----------------------------------------------------------------------
|
239
|
+
|
240
|
+
l_title 'Push Changes and Synchronize Master/Develop'
|
241
|
+
|
242
|
+
${SCRIPT_DIR}/${SYNC_SCRIPT}
|
243
|
+
|
244
|
+
l_heading 'Success'
|
data/bin/setup
ADDED
data/hooks/pre-commit
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'English'
|
5
|
+
|
6
|
+
# NOTE: you may need change file permissions
|
7
|
+
# chmod +x hooks/pre-commit
|
8
|
+
|
9
|
+
exit 0 if ARGV.include?('--no-verify')
|
10
|
+
|
11
|
+
warning_keywords = %w[console.log]
|
12
|
+
keywords = %w[binding.pry console.dir byebug debugger]
|
13
|
+
files_changed = `git diff-index --name-only HEAD --`.split
|
14
|
+
|
15
|
+
# puts '----------------------------------------------------------------------'
|
16
|
+
# puts remove files changed from the pre-commit checking if they are one of the following files
|
17
|
+
# puts '----------------------------------------------------------------------'
|
18
|
+
# files_changed = files_changed - ['hooks/pre-commit']
|
19
|
+
# files_changed = files_changed - ['hooks/update-version']
|
20
|
+
|
21
|
+
# byebug may need to be in these files
|
22
|
+
files_changed -= ['Gemfile']
|
23
|
+
files_changed -= ['Gemfile.lock']
|
24
|
+
files_changed -= ['.gitignore']
|
25
|
+
files_changed -= ['README.md']
|
26
|
+
|
27
|
+
files_changed = files_changed.reject { |f| f.downcase.end_with?('.json') }
|
28
|
+
files_changed = files_changed.reject { |f| f.downcase.end_with?('.yml') }
|
29
|
+
|
30
|
+
# ignore files from specific folders
|
31
|
+
|
32
|
+
file_groups = files_changed.select do |item|
|
33
|
+
item.start_with?('hooks') # ||
|
34
|
+
# item.start_with?('lib/generators')
|
35
|
+
end
|
36
|
+
|
37
|
+
files_changed -= file_groups
|
38
|
+
|
39
|
+
# remove files that are changed because they are deleted
|
40
|
+
files_changed = files_changed.select { |filename| File.file?(filename) }
|
41
|
+
|
42
|
+
# puts '----------------------------------------------------------------------'
|
43
|
+
# puts 'Files Changed'
|
44
|
+
# puts '----------------------------------------------------------------------'
|
45
|
+
# puts files_changed
|
46
|
+
# puts '----------------------------------------------------------------------'
|
47
|
+
|
48
|
+
unless files_changed.length.zero?
|
49
|
+
# puts "#{keywords.join('|')}"
|
50
|
+
# puts "#{files_changed.join(' ')}"
|
51
|
+
|
52
|
+
`git grep -q -E "#{warning_keywords.join('|')}" #{files_changed.join(' ')}`
|
53
|
+
|
54
|
+
if $CHILD_STATUS.exitstatus.zero?
|
55
|
+
puts '' # Check following lines:''
|
56
|
+
puts $CHILD_STATUS.exitstatus
|
57
|
+
files_changed.each do |file|
|
58
|
+
warning_keywords.each do |keyword|
|
59
|
+
# puts "#{keyword} ::: #{file}"
|
60
|
+
`git grep -q -E #{keyword} #{file}`
|
61
|
+
if $CHILD_STATUS.exitstatus.zero?
|
62
|
+
line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
|
63
|
+
puts "WARNING:\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
`git grep -q -E "#{keywords.join('|')}" #{files_changed.join(' ')}`
|
70
|
+
|
71
|
+
if $CHILD_STATUS.exitstatus.zero?
|
72
|
+
puts '' # Check following lines:''
|
73
|
+
puts $CHILD_STATUS.exitstatus
|
74
|
+
files_changed.each do |file|
|
75
|
+
keywords.each do |keyword|
|
76
|
+
# puts "#{keyword} ::: #{file}"
|
77
|
+
`git grep -q -E #{keyword} #{file}`
|
78
|
+
if $CHILD_STATUS.exitstatus.zero?
|
79
|
+
line = `git grep -n #{keyword} #{file} | awk -F ":" '{print $2}'`.split.join(', ')
|
80
|
+
puts "ERROR :\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
puts '# Force commit with --no-verify'
|
85
|
+
exit 1
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# NOTE: you may need change file permissions
|
5
|
+
# chmod +x hooks/update-version
|
6
|
+
|
7
|
+
exit 1 if ARGV.empty?
|
8
|
+
|
9
|
+
version = ARGV[0]
|
10
|
+
version = version[1..-1] # revoke 'v' character, e.g. v0.1.1 becomes 0.1.1
|
11
|
+
|
12
|
+
namespaces = %w[KUtil]
|
13
|
+
|
14
|
+
indent = 0
|
15
|
+
output = ['# frozen_string_literal: true', '']
|
16
|
+
|
17
|
+
namespaces.each do |namespace|
|
18
|
+
output.push "#{' ' * indent}module #{namespace}"
|
19
|
+
indent += 1
|
20
|
+
end
|
21
|
+
|
22
|
+
output.push "#{' ' * indent}VERSION = \'#{version}'"
|
23
|
+
indent -= 1
|
24
|
+
|
25
|
+
namespaces.each do
|
26
|
+
output.push "#{' ' * indent}end"
|
27
|
+
indent -= 1
|
28
|
+
end
|
29
|
+
|
30
|
+
output.push('')
|
31
|
+
|
32
|
+
printf "%-25<label>s : %<version>s\n", label: 'GEM VERSION', version: version
|
33
|
+
File.open('lib/k_util/version.rb', 'w+') { |f| f.write(output.join("\n")) }
|
data/k_util.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/k_util/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = '>= 2.5'
|
7
|
+
spec.name = 'k_util'
|
8
|
+
spec.version = KUtil::VERSION
|
9
|
+
spec.authors = ['David Cruwys']
|
10
|
+
spec.email = ['david@ideasmen.com.au']
|
11
|
+
|
12
|
+
spec.summary = 'KUtil provides simple utility methods'
|
13
|
+
spec.description = <<-TEXT
|
14
|
+
KUtil provides simple utility methods
|
15
|
+
TEXT
|
16
|
+
spec.homepage = 'http://appydave.com/gems/k-util'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
22
|
+
|
23
|
+
# spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
|
24
|
+
|
25
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
26
|
+
spec.metadata['source_code_uri'] = 'https://github.com/klueless-io/k_util'
|
27
|
+
spec.metadata['changelog_uri'] = 'https://github.com/klueless-io/k_util/commits/master'
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the RubyGem files that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
33
|
+
f.match(%r{^(test|spec|features)/})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
# spec.extensions = ['ext/k_util/extconf.rb']
|
40
|
+
|
41
|
+
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
42
|
+
end
|
data/lib/k_util.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# module KDsl
|
4
|
+
# # File utilities
|
5
|
+
# module Util
|
6
|
+
# class << self
|
7
|
+
# attr_accessor :data
|
8
|
+
# end
|
9
|
+
|
10
|
+
# # Helper methods attached to the namespace for working with Data
|
11
|
+
# class DataHelper
|
12
|
+
# # Convert a hash into a deep OpenStruct or array an array
|
13
|
+
# # of objects into an array of OpenStruct
|
14
|
+
# def self.to_struct(data)
|
15
|
+
# if data.is_a?(Hash)
|
16
|
+
# return OpenStruct.new(data.map { |k,v| [k, to_struct(v)] }.to_h )
|
17
|
+
|
18
|
+
# elsif data.is_a?(Array)
|
19
|
+
# return data.map { |o| to_struct(o) }
|
20
|
+
|
21
|
+
# else
|
22
|
+
# # Some primitave type: String, True/False, Symbol or an ObjectStruct
|
23
|
+
# return data
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
# def self.struct_to_hash(data)
|
28
|
+
# # No test yet
|
29
|
+
# if data.is_a?(Array)
|
30
|
+
# return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
31
|
+
# end
|
32
|
+
|
33
|
+
# data.each_pair.with_object({}) do |(key, value), hash|
|
34
|
+
# if value.is_a?(OpenStruct)
|
35
|
+
# hash[key] = struct_to_hash(value)
|
36
|
+
# elsif value.is_a?(Array)
|
37
|
+
# # No test yet
|
38
|
+
# values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
39
|
+
# hash[key] = values
|
40
|
+
# else
|
41
|
+
# hash[key] = value
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# # Generate hyper link encoded string for the console
|
47
|
+
# def self.console_file_hyperlink(text, file)
|
48
|
+
# "\u001b]8;;file://#{file}\u0007#{text}\u001b]8;;\u0007"
|
49
|
+
# end
|
50
|
+
|
51
|
+
# def self.console_hyperlink(text, link)
|
52
|
+
# "\u001b]8;;#{link}\u0007#{text}\u001b]8;;\u0007"
|
53
|
+
# end
|
54
|
+
|
55
|
+
# def self.clean_symbol(value)
|
56
|
+
# return value if value.nil?
|
57
|
+
|
58
|
+
# value.is_a?(Symbol) ? value.to_s : value
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
64
|
+
# KDsl::Util.data = KDsl::Util::DataHelper
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# module KDsl
|
4
|
+
# # File utilities
|
5
|
+
# module Util
|
6
|
+
# class << self
|
7
|
+
# attr_accessor :file
|
8
|
+
# end
|
9
|
+
|
10
|
+
# # Helper methods attached to the namespace for working with Files
|
11
|
+
# class FileHelper
|
12
|
+
# def self.expand_path(filename, base_path)
|
13
|
+
# if pathname_absolute?(filename)
|
14
|
+
# filename
|
15
|
+
# elsif filename.start_with?('~/')
|
16
|
+
# File.expand_path(filename)
|
17
|
+
# else
|
18
|
+
# File.expand_path(filename, base_path)
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
# def self.pathname_absolute?(pathname)
|
23
|
+
# Pathname.new(pathname).absolute?
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
# KDsl::Util.file = KDsl::Util::FileHelper
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: k_util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Cruwys
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: " KUtil provides simple utility methods\n"
|
14
|
+
email:
|
15
|
+
- david@ideasmen.com.au
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/main.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Guardfile
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- STORIES.md
|
31
|
+
- USAGE.md
|
32
|
+
- bin/console
|
33
|
+
- bin/k
|
34
|
+
- bin/kgitsync
|
35
|
+
- bin/khotfix
|
36
|
+
- bin/setup
|
37
|
+
- hooks/pre-commit
|
38
|
+
- hooks/update-version
|
39
|
+
- k_util.gemspec
|
40
|
+
- lib/k_util.rb
|
41
|
+
- lib/k_util/data_helper.rb
|
42
|
+
- lib/k_util/file_helper.rb
|
43
|
+
- lib/k_util/version.rb
|
44
|
+
homepage: http://appydave.com/gems/k-util
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata:
|
48
|
+
homepage_uri: http://appydave.com/gems/k-util
|
49
|
+
source_code_uri: https://github.com/klueless-io/k_util
|
50
|
+
changelog_uri: https://github.com/klueless-io/k_util/commits/master
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.5'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.2.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: KUtil provides simple utility methods
|
70
|
+
test_files: []
|