aid 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d410aaa006c361b0a2def56ab77ed4e4cbb7e7f
4
+ data.tar.gz: cbe5fbe9a404339b9da151f7c09e30e654993308
5
+ SHA512:
6
+ metadata.gz: dd862dbea28b6ec45c838178cbe17d34b2c8d7034cb9b0ec6c8fd507646a2ebcfeafbd788172bf3669b0c69e32ae7cadb0dd70fb02ccd280554cc83e974d17fc
7
+ data.tar.gz: bfd5c74b562d001a650a39dbbc4c79004ef153a58fa157b4362835f5a64578b84738d9c97f60a7311ca7f333caebd858f2110a6f8c0912833f96f3f6528193a6
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ /.aide
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) do |repo_name|
4
+ "https://github.com/#{repo_name}"
5
+ end
6
+
7
+ # Specify your gem's dependencies in aide.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 David Balatero
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.
@@ -0,0 +1,39 @@
1
+ # Aide
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aide`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aide'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aide
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dbalatero/aide.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "aid/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aid"
8
+ spec.version = Aid::VERSION
9
+ spec.authors = ["David Balatero"]
10
+ spec.email = ["dbalatero@gmail.com"]
11
+
12
+ spec.summary = %q{A library to make repo scripts easy and discoverable.}
13
+ spec.homepage = "https://github.com/dbalatero/aid"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
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.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aide"
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__)
@@ -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
data/exe/aid ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/aid"
4
+
5
+ Aid.load_scripts!
6
+
7
+ script = Aid::Script.scripts[Aid.script_name]
8
+
9
+ if ARGV.empty?
10
+ Aid::Scripts::Help.run
11
+ exit 0
12
+ end
13
+
14
+ if script
15
+ script.run(*Aid.script_args)
16
+ else
17
+ puts "Script '#{script}' not recognized"
18
+ puts
19
+
20
+ Aid::Scripts::Help.run
21
+
22
+ exit 1
23
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "aid/version"
2
+
3
+ module Aid
4
+ def self.load_paths
5
+ @load_paths ||= [
6
+ File.expand_path(File.dirname(__FILE__) + "/aid/scripts"),
7
+ ".aid",
8
+ ENV['AID_PATH']
9
+ ].compact
10
+ end
11
+
12
+ def self.load_scripts!
13
+ load_paths.each do |path|
14
+ Dir.glob("#{path}/**/*.rb").each do |file|
15
+ require File.expand_path(file)
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.script_name
21
+ ARGV.first
22
+ end
23
+
24
+ def self.script_args
25
+ ARGV[1..-1]
26
+ end
27
+ end
28
+
29
+ require_relative "aid/colorize"
30
+ require_relative "aid/inheritable"
31
+ require_relative "aid/script"
32
+ require_relative "aid/scripts"
@@ -0,0 +1,39 @@
1
+ module Aid::Colorize
2
+ extend self
3
+
4
+ def self.included(base)
5
+ colorize = self
6
+
7
+ base.class_eval do
8
+ extend colorize
9
+ end
10
+ end
11
+
12
+ COLOR_CODES = {
13
+ black: 30,
14
+ blue: 34,
15
+ brown: 33,
16
+ cyan: 36,
17
+ dark_gray: 90,
18
+ green: 32,
19
+ light_blue: 94,
20
+ light_cyan: 96,
21
+ light_gray: 37,
22
+ light_green: 92,
23
+ light_purple: 95,
24
+ light_red: 91,
25
+ light_yellow: 93,
26
+ purple: 35,
27
+ red: 31,
28
+ white: 97,
29
+ yellow: 33,
30
+
31
+ command: 96,
32
+ error: 91,
33
+ info: 93,
34
+ }
35
+
36
+ def colorize(color, string)
37
+ "\e[#{COLOR_CODES[color]}m#{string}\e[0m"
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ module Aid
2
+ module Inheritable
3
+ def self.included(klass)
4
+ klass.instance_eval do
5
+ extend ClassMethods
6
+
7
+ def self.inherited(subklass)
8
+ self.script_classes << subklass
9
+ end
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def script_classes
15
+ @script_classes ||= []
16
+ end
17
+
18
+ def reset_script_classes!
19
+ @scripts = nil
20
+ @script_classes = []
21
+ end
22
+
23
+ def scripts
24
+ @scripts ||= load_scripts_deferred
25
+ end
26
+
27
+ def load_scripts_deferred
28
+ script_classes.reduce(Hash.new) do |result, klass|
29
+ result[klass.name] = klass
30
+ result
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,70 @@
1
+ module Aid
2
+ class Script
3
+ include Aid::Colorize
4
+ include Aid::Inheritable
5
+
6
+ def self.name
7
+ klass_name = self.to_s.split('::').last
8
+
9
+ klass_name
10
+ .scan(/[A-Z][a-z0-9]*/)
11
+ .map(&:downcase)
12
+ .join('-')
13
+ end
14
+
15
+ def exit_with_help!
16
+ puts self.class.help
17
+ exit
18
+ end
19
+
20
+ def self.help
21
+ <<~HELP
22
+ Help has not been implemented for "#{name}". Please implement a
23
+ help method like so:
24
+
25
+ class #{self} < Aid::Script
26
+ def self.help
27
+ <<-EOF
28
+ My awesome help message here.
29
+ This will be so useful for people.
30
+ EOF
31
+ end
32
+ end
33
+ HELP
34
+ end
35
+
36
+ def self.description
37
+ ""
38
+ end
39
+
40
+ attr_reader :argv
41
+
42
+ def initialize(*argv)
43
+ @argv = *argv
44
+ end
45
+
46
+ def self.run(*argv)
47
+ new(*argv).run
48
+ end
49
+
50
+ def run
51
+ raise NotImplementedError
52
+ end
53
+
54
+ def system!(*args)
55
+ puts colorize(:command, args.join(" "))
56
+ system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
57
+ end
58
+
59
+ def step(name)
60
+ puts colorize(:info, "\n== #{name} ==")
61
+ yield if block_given?
62
+ end
63
+
64
+ private
65
+
66
+ def aid_directory
67
+ "./.aid"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ module Aid
2
+ module Scripts
3
+ end
4
+ end
@@ -0,0 +1,57 @@
1
+ module Aid
2
+ module Scripts
3
+ class Help < Aid::Script
4
+ attr_reader :script
5
+
6
+ def initialize(*argv)
7
+ super
8
+
9
+ script_name = argv.first
10
+ @script = Aid::Script.scripts[script_name]
11
+ end
12
+
13
+ def self.description
14
+ "Displays help information"
15
+ end
16
+
17
+ def self.help
18
+ ""
19
+ end
20
+
21
+ def run
22
+ if script
23
+ puts "Help for #{colorize(:light_blue, script.name)}:"
24
+
25
+ puts script.help
26
+ puts
27
+ else
28
+ basic_usage
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def basic_usage
35
+ puts "Usage: aid #{colorize(:light_blue, '[script name]')}"
36
+ puts
37
+ puts "Specify a specific script to run, options are: "
38
+ puts
39
+
40
+ names_and_descriptions = Aid::Script.scripts.map do |name, script|
41
+ [
42
+ colorize(:light_green, name),
43
+ colorize(:light_blue, script.description)
44
+ ]
45
+ end
46
+
47
+ padding = names_and_descriptions.map { |name, _| name.length }.max
48
+
49
+ names_and_descriptions.each do |name, description|
50
+ puts " %-#{padding}s %s" % [name, description]
51
+ end
52
+
53
+ puts
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ module Aid
2
+ module Scripts
3
+ class Init < Aid::Script
4
+ def self.description
5
+ "Sets up aid in your project"
6
+ end
7
+
8
+ def run
9
+ step "Creating .aid directory" do
10
+ system! "mkdir -p #{aid_directory}"
11
+ end
12
+
13
+ puts
14
+ puts "All done! To create your first script, run "\
15
+ "#{colorize(:green, "aid new [script-name]")}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ module Aid
2
+ module Scripts
3
+ class New < Aid::Script
4
+ def self.description
5
+ "Generates a new script in the aid directory"
6
+ end
7
+
8
+ def self.help
9
+ <<~HELP
10
+ Usage: aid new [script name]
11
+
12
+ Generates a new script file in the aid script directory.
13
+
14
+ Example:
15
+ #{colorize(:green, "$ aid new my-script-name")}
16
+
17
+ will generate a new script called my_script_name.rb
18
+ HELP
19
+ end
20
+
21
+ def run
22
+ exit_with_help! unless script_name
23
+ check_for_aid_directory!
24
+
25
+ step "Creating #{output_path}" do
26
+ File.open(output_path, "wb") do |fp|
27
+ fp.write(template)
28
+ end
29
+
30
+ puts
31
+ print "Successfully created "
32
+ puts colorize(:green, output_path)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def output_path
39
+ "#{aid_directory}/#{output_filename}"
40
+ end
41
+
42
+ def output_filename
43
+ "#{script_name.gsub(/-/, "_")}.rb"
44
+ end
45
+
46
+ def check_for_aid_directory!
47
+ unless Dir.exist?(aid_directory)
48
+ abort "The #{colorize(:green, aid_directory)} directory is "\
49
+ "missing. Please run #{colorize(:green, "aid init")} to create it."
50
+ end
51
+ end
52
+
53
+ def template
54
+ <<~RUBY
55
+ class #{class_name} < Aid::Script
56
+ def self.description
57
+ "FILL ME IN"
58
+ end
59
+
60
+ def self.help
61
+ <<~HELP
62
+ Fill me in.
63
+ HELP
64
+ end
65
+
66
+ def run
67
+ end
68
+ end
69
+ RUBY
70
+ end
71
+
72
+ def class_name
73
+ script_name
74
+ .split("-")
75
+ .map { |token| token[0].upcase + token[1..-1] }
76
+ .join
77
+ end
78
+
79
+ def script_name
80
+ argv.first
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Aid
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Balatero
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-01 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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:
56
+ email:
57
+ - dbalatero@gmail.com
58
+ executables:
59
+ - aid
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - aid.gemspec
71
+ - bin/console
72
+ - bin/setup
73
+ - exe/aid
74
+ - lib/aid.rb
75
+ - lib/aid/colorize.rb
76
+ - lib/aid/inheritable.rb
77
+ - lib/aid/script.rb
78
+ - lib/aid/scripts.rb
79
+ - lib/aid/scripts/help.rb
80
+ - lib/aid/scripts/init.rb
81
+ - lib/aid/scripts/new.rb
82
+ - lib/aid/version.rb
83
+ homepage: https://github.com/dbalatero/aid
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.6.11
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: A library to make repo scripts easy and discoverable.
107
+ test_files: []