gotta-mod 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +10 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dev-setup.sh +28 -0
- data/gotta-mod.gemspec +44 -0
- data/lib/gotta/mod.rb +41 -0
- data/lib/gotta/mod/cli/commands.rb +1 -0
- data/lib/gotta/mod/cli/new.rb +17 -0
- data/lib/gotta/mod/event.rb +44 -0
- data/lib/gotta/mod/hub.rb +87 -0
- data/lib/gotta/mod/listener.rb +47 -0
- data/lib/gotta/mod/mod.rb +49 -0
- data/lib/gotta/mod/monkey_patch.rb +37 -0
- data/lib/gotta/mod/project.rb +36 -0
- data/lib/gotta/mod/version.rb +7 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dffbe2fab15b0bc117d98110717732176d932ada50899df7a733b3245d56e3eb
|
4
|
+
data.tar.gz: 7c89416f876084ed357beeef168141caf75d350a274b0f50d5af031b844d369d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8901b3e156889aeabb0a0edde0cc43716efb835dac67897bf0f5bd4dd50624d954dbdde628ef9f8bd02d4d373cfbb2f854dafa9e2a00864e339c7c2cd5d7f0ef
|
7
|
+
data.tar.gz: 1736f17e8d5357f25ce2d4fcbb6cc9f6231f57c426a453c4a707c19e9fbf2816c069c8c4bce7d975cbf7ab1c2bdc39e7c4a490c7616a1da157ea7fcb9c51c2e5
|
data/.gitignore
ADDED
data/.rspec
ADDED
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 paulo@parruda.net. 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
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gotta-mod (0.1.1)
|
5
|
+
listen (~> 3.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
ffi (1.11.1)
|
12
|
+
listen (3.1.5)
|
13
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
14
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
15
|
+
ruby_dep (~> 1.2)
|
16
|
+
rake (10.5.0)
|
17
|
+
rb-fsevent (0.10.3)
|
18
|
+
rb-inotify (0.10.0)
|
19
|
+
ffi (~> 1.0)
|
20
|
+
rspec (3.8.0)
|
21
|
+
rspec-core (~> 3.8.0)
|
22
|
+
rspec-expectations (~> 3.8.0)
|
23
|
+
rspec-mocks (~> 3.8.0)
|
24
|
+
rspec-core (3.8.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-expectations (3.8.3)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-mocks (3.8.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-support (3.8.0)
|
33
|
+
ruby_dep (1.5.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 2.0)
|
40
|
+
gotta-mod!
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Paulo Arruda
|
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
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gotta/mod"
|
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
data/dev-setup.sh
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -e
|
3
|
+
! which rvm && echo "Sorry, but this script only works with RVM" && exit 1
|
4
|
+
[[ -z $GEM_HOME ]] && echo "You need to have \$GEM_HOME set before continuing." && exit 1
|
5
|
+
GEMS=$GEM_HOME/gems
|
6
|
+
echo Gems detected at: $GEMS
|
7
|
+
#which gotta-mod &&
|
8
|
+
echo "Removing all installed versions" && gem uninstall -a -I -x gotta-mod
|
9
|
+
echo "Cleaning up stale links"
|
10
|
+
rm -rf $GEMS/gotta-mod-0*
|
11
|
+
echo "Building gem from source"
|
12
|
+
VERSION=$(gem build gotta-mod.gemspec |grep Version|cut -f4 -d" ")
|
13
|
+
echo "Installing new gem"
|
14
|
+
gem install gotta-mod-$VERSION.gem
|
15
|
+
SOURCECODE=$PWD
|
16
|
+
INSTALL_DIR=$GEMS/gotta-mod-$VERSION
|
17
|
+
echo -e "\n\nThe directory below is about to be removed. Press ENTER to continue or CTRL+C to abort."
|
18
|
+
echo $INSTALL_DIR
|
19
|
+
read
|
20
|
+
rm -rf $INSTALL_DIR
|
21
|
+
echo "Creating symlink $INSTALL_DIR -> $SOURCECODE"
|
22
|
+
ln -s $SOURCECODE $INSTALL_DIR
|
23
|
+
echo "Running 'gotta-mod -v'"
|
24
|
+
touch ".test"
|
25
|
+
[[ -e $INSTALL_DIR/.test ]] && rm .test && echo Done && exit 0
|
26
|
+
rm -f .test
|
27
|
+
echo "ERROR: The symbolik link $INSTALL_DIR is not working."
|
28
|
+
exit 1
|
data/gotta-mod.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gotta/mod/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gotta-mod"
|
8
|
+
spec.version = Gotta::Mod::VERSION
|
9
|
+
spec.authors = ["Paulo Arruda"]
|
10
|
+
spec.email = ["parrudaj@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gotta Framework? Now customize it with Mods}
|
13
|
+
spec.description = %q{Customize gotta development environment with Mods}
|
14
|
+
spec.homepage = "https://github.com/gotta-open-source/gotta-mod"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'listen', '~> 3.1'
|
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
|
+
if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
+
|
24
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
25
|
+
spec.metadata["source_code_uri"] = "https://github.com/gotta-open-source/gotta-mod"
|
26
|
+
spec.metadata["changelog_uri"] = "https://github.com/gotta-open-source/gotta-mod/blob/master/CHANGELOG.md"
|
27
|
+
else
|
28
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
29
|
+
"public gem pushes."
|
30
|
+
end
|
31
|
+
|
32
|
+
# Specify which files should be added to the gem when it is released.
|
33
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
34
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
35
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
36
|
+
end
|
37
|
+
spec.bindir = "exe"
|
38
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
39
|
+
spec.require_paths = ["lib"]
|
40
|
+
|
41
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
42
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
44
|
+
end
|
data/lib/gotta/mod.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "listen"
|
4
|
+
require "gotta/mod/version"
|
5
|
+
require "gotta/mod/monkey_patch"
|
6
|
+
require "gotta/mod/project"
|
7
|
+
require "gotta/mod/event"
|
8
|
+
require "gotta/mod/listener"
|
9
|
+
require "gotta/mod/hub"
|
10
|
+
require "gotta/mod/mod"
|
11
|
+
|
12
|
+
module Gotta
|
13
|
+
module Mod
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
def self.hub=(hub)
|
17
|
+
@@hub = hub
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.hub
|
21
|
+
@@hub
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.now(dir: Dir.pwd)
|
25
|
+
project = Gotta::Project.new(dir)
|
26
|
+
Gotta::Project.config = project.config
|
27
|
+
listener = Listener.new(working_directory: dir)
|
28
|
+
self.hub = Hub.new(listener.queue)
|
29
|
+
hub_thread = Thread.new {hub.start} # Hub runs on a separate thread.
|
30
|
+
|
31
|
+
# Now require all `main.rb` files inside the mods folder
|
32
|
+
Dir.glob("#{project.config["mods_dir"]}/*") do |f|
|
33
|
+
rbfile = "#{f}/#{File.basename(f)}.rb"
|
34
|
+
Mod.class_eval(File.read(rbfile), rbfile)
|
35
|
+
end
|
36
|
+
listener.start
|
37
|
+
puts "Gotta start using it now."
|
38
|
+
sleep
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "new"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Gotta
|
2
|
+
module Mod
|
3
|
+
module CLI
|
4
|
+
class NewMod
|
5
|
+
def initialize(args)
|
6
|
+
@args = args
|
7
|
+
end
|
8
|
+
|
9
|
+
def run!
|
10
|
+
puts "Received args #{@args}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
::Gotta::CLI::Command.register("new mod", ::Gotta::Mod::CLI::NewMod)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gotta
|
4
|
+
module Mod
|
5
|
+
class Event
|
6
|
+
attr_reader :type,
|
7
|
+
:filename,
|
8
|
+
:absolute_path,
|
9
|
+
:path,
|
10
|
+
:working_directory
|
11
|
+
|
12
|
+
def initialize(type:, absolute_path:, working_directory:)
|
13
|
+
@working_directory = working_directory
|
14
|
+
@absolute_path = absolute_path
|
15
|
+
@path = relative_path_for(@absolute_path.dup)
|
16
|
+
@filename = File.basename(@absolute_path)
|
17
|
+
@type = type
|
18
|
+
make_it_immutable
|
19
|
+
end
|
20
|
+
|
21
|
+
def added?
|
22
|
+
@type == :added
|
23
|
+
end
|
24
|
+
|
25
|
+
def modified?
|
26
|
+
@type == :modified
|
27
|
+
end
|
28
|
+
|
29
|
+
def removed?
|
30
|
+
@type == :removed
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def relative_path_for(pth)
|
35
|
+
pth.slice!("#{working_directory}/")
|
36
|
+
pth
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_it_immutable
|
40
|
+
freeze
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gotta
|
4
|
+
module Mod
|
5
|
+
require "set"
|
6
|
+
|
7
|
+
# Starts a new thread and goes on a blocking
|
8
|
+
# operation to constantly pop values from the
|
9
|
+
# event queue.
|
10
|
+
# If the file changed resides within a directory
|
11
|
+
# that is being monitored by the hub, all the
|
12
|
+
# mods that monitor that file will be executed.
|
13
|
+
# The execution of the mod code is done asynchronously
|
14
|
+
# on a separate thread.
|
15
|
+
class Hub
|
16
|
+
attr_reader :queue, :mods
|
17
|
+
def initialize(queue)
|
18
|
+
# This is the separator to generate the key
|
19
|
+
# for the mods hash.
|
20
|
+
@key_separator = ":::"
|
21
|
+
@queue = queue
|
22
|
+
@mutex = Mutex.new
|
23
|
+
@mods = {}
|
24
|
+
@paths = Set.new
|
25
|
+
@threads = Set.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
loop do
|
30
|
+
begin
|
31
|
+
event = queue.pop
|
32
|
+
keys = get_matching_paths_for(event)
|
33
|
+
next unless keys.any?
|
34
|
+
run_mods(event, keys)
|
35
|
+
rescue StandardError => e
|
36
|
+
puts e.full_message
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add mods to certain events on a certain path.
|
43
|
+
# 'path' is relative to the project folder
|
44
|
+
# 'on' is :added or :modified or :removed
|
45
|
+
def register_mod(mod_name:, path:, on:, &block)
|
46
|
+
key = "#{path}#{@key_separator}#{on}"
|
47
|
+
@mutex.synchronize {
|
48
|
+
@mods[key] ||= []
|
49
|
+
@mods[key] << [block, mod_name]
|
50
|
+
@paths << path
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
# Execute the mod code in a separate thread
|
56
|
+
def run_mods(event, keys)
|
57
|
+
# puts "Running mods for event #{event.inspect}"
|
58
|
+
@mutex.synchronize {
|
59
|
+
keys.each do |key|
|
60
|
+
# puts "Processing key #{key}"
|
61
|
+
next unless @mods[key]
|
62
|
+
@threads << @mods[key].map do |blk, mod_name|
|
63
|
+
Thread.new do
|
64
|
+
# puts "Running mod #{mod_name}"
|
65
|
+
blk.call(event)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check if the @mods hash has a key with
|
73
|
+
# the file/directory path, a separator and the event type.
|
74
|
+
# `event.type` can be :added or :modified or :removed
|
75
|
+
def get_matching_paths_for(event)
|
76
|
+
# puts "MONITORED? #{event.path}#{@key_separator}#{event.type}"
|
77
|
+
@mutex.synchronize {
|
78
|
+
@paths.map do |p|
|
79
|
+
# puts "#{p} -> #{event.path} (#{File.fnmatch(p, event.path)})"
|
80
|
+
next unless File.fnmatch(p, event.path)
|
81
|
+
"#{p}#{@key_separator}#{event.type}"
|
82
|
+
end.compact
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gotta
|
4
|
+
module Mod
|
5
|
+
class Listener
|
6
|
+
attr_reader :listener, :working_directory, :queue
|
7
|
+
def initialize(working_directory:)
|
8
|
+
@working_directory = working_directory
|
9
|
+
@queue = Queue.new
|
10
|
+
@listener = ::Listen.to(working_directory, &callback)
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
listener.start
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
listener.stop
|
19
|
+
end
|
20
|
+
|
21
|
+
def callback
|
22
|
+
Proc.new do |modified, added, removed|
|
23
|
+
begin
|
24
|
+
modified.each do |file|
|
25
|
+
queue.push Event.new(type: :modified,
|
26
|
+
absolute_path: file,
|
27
|
+
working_directory: working_directory)
|
28
|
+
end
|
29
|
+
added.each do |file|
|
30
|
+
queue.push Event.new(type: :added,
|
31
|
+
absolute_path: file,
|
32
|
+
working_directory: working_directory)
|
33
|
+
end
|
34
|
+
removed.each do |file|
|
35
|
+
queue.push Event.new(type: :removed,
|
36
|
+
absolute_path: file,
|
37
|
+
working_directory: working_directory)
|
38
|
+
end
|
39
|
+
rescue StandardError => e
|
40
|
+
puts e.full_message
|
41
|
+
next
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gotta
|
4
|
+
module Mod
|
5
|
+
class Mod
|
6
|
+
|
7
|
+
def build(name, &block)
|
8
|
+
new(name: name, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :name,
|
12
|
+
:description,
|
13
|
+
:version
|
14
|
+
|
15
|
+
def initialize(name:, &block)
|
16
|
+
@name = name
|
17
|
+
instance_eval(&block)
|
18
|
+
@hub = Mod.hub
|
19
|
+
puts "Mod '#{name}' registered."
|
20
|
+
end
|
21
|
+
|
22
|
+
def version(ver)
|
23
|
+
@version = ver
|
24
|
+
end
|
25
|
+
|
26
|
+
def description(desc)
|
27
|
+
@description = desc
|
28
|
+
end
|
29
|
+
|
30
|
+
def project
|
31
|
+
Gotta::Project.config
|
32
|
+
end
|
33
|
+
|
34
|
+
def on(type, &block)
|
35
|
+
@hub.register_mod(
|
36
|
+
mod_name: name,
|
37
|
+
path: @filter,
|
38
|
+
on: type,
|
39
|
+
&block
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def watch(filter, &block)
|
44
|
+
@filter = filter
|
45
|
+
instance_eval &block
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is required to address a bug on the Listen gem :(
|
4
|
+
# See: https://github.com/guard/listen/issues/426
|
5
|
+
module Listen
|
6
|
+
class Record
|
7
|
+
def dir_entries(rel_path)
|
8
|
+
subtree =
|
9
|
+
if [nil, '', '.'].include? rel_path.to_s
|
10
|
+
tree
|
11
|
+
else
|
12
|
+
_sub_dir_entries(rel_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
result = {}
|
16
|
+
subtree.each do |key, values|
|
17
|
+
# Only get data for file entries
|
18
|
+
result[key] = values.key?(:mtime) ? values : {}
|
19
|
+
end
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def _sub_dir_entries(rel_path)
|
24
|
+
result = {}
|
25
|
+
tree.each do |path, meta|
|
26
|
+
next if !path.start_with?(rel_path)
|
27
|
+
if path == rel_path
|
28
|
+
result.merge!(meta)
|
29
|
+
else
|
30
|
+
sub_path = path.sub(%r{\A#{rel_path}/?}, '')
|
31
|
+
result[sub_path] = meta
|
32
|
+
end
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gotta
|
4
|
+
require "yaml"
|
5
|
+
class Project
|
6
|
+
class << self
|
7
|
+
attr_accessor :config
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :dir, :config, :config_file_path
|
11
|
+
def initialize(dir)
|
12
|
+
@dir = dir
|
13
|
+
@config_file_path = "#{dir}/project.yml"
|
14
|
+
@config = read_config
|
15
|
+
@config["mods_dir"] ||= "mods"
|
16
|
+
@config["functions_dir"] ||= "functions"
|
17
|
+
@config["public_dir"] ||= "public"
|
18
|
+
check_mods_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def check_mods_dir
|
24
|
+
Dir.mkdir(@config["mods_dir"]) unless File.directory?(@config["mods_dir"])
|
25
|
+
end
|
26
|
+
|
27
|
+
def read_config #=> {}
|
28
|
+
load_file || {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_file
|
32
|
+
return nil unless File.file?(config_file_path)
|
33
|
+
YAML.load(File.read(config_file_path)) rescue nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gotta-mod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paulo Arruda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: listen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Customize gotta development environment with Mods
|
70
|
+
email:
|
71
|
+
- parrudaj@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- dev-setup.sh
|
87
|
+
- gotta-mod.gemspec
|
88
|
+
- lib/gotta/mod.rb
|
89
|
+
- lib/gotta/mod/cli/commands.rb
|
90
|
+
- lib/gotta/mod/cli/new.rb
|
91
|
+
- lib/gotta/mod/event.rb
|
92
|
+
- lib/gotta/mod/hub.rb
|
93
|
+
- lib/gotta/mod/listener.rb
|
94
|
+
- lib/gotta/mod/mod.rb
|
95
|
+
- lib/gotta/mod/monkey_patch.rb
|
96
|
+
- lib/gotta/mod/project.rb
|
97
|
+
- lib/gotta/mod/version.rb
|
98
|
+
homepage: https://github.com/gotta-open-source/gotta-mod
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata:
|
102
|
+
homepage_uri: https://github.com/gotta-open-source/gotta-mod
|
103
|
+
source_code_uri: https://github.com/gotta-open-source/gotta-mod
|
104
|
+
changelog_uri: https://github.com/gotta-open-source/gotta-mod/blob/master/CHANGELOG.md
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.7.8
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Gotta Framework? Now customize it with Mods
|
125
|
+
test_files: []
|