gotta-mod 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +0 -5
- data/lib/gotta/mod.rb +9 -9
- data/lib/gotta/mod/cli/commands.rb +1 -1
- data/lib/gotta/mod/cli/watch.rb +20 -0
- data/lib/gotta/mod/hub.rb +22 -1
- data/lib/gotta/mod/{mod.rb → mod_builder.rb} +6 -6
- data/lib/gotta/mod/project.rb +7 -5
- data/lib/gotta/mod/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cddb21ae617ea4908ec5074b0f284a65a92847d2c973c47f4cac7d1e42671994
|
4
|
+
data.tar.gz: d01212517c946a46de68764f60baa90636bdb050ffe36b03c396bcba0e879b56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72c57e501a57bb5a9690ab03e518c9fe7b29f3b4300810f77058a9e2a77a5b87bada1c8bfc1eeb11d752b9d7726ca65266af20600574fb773c018e0a7b71b52b
|
7
|
+
data.tar.gz: b95c7bb86fa24111b2331c26f60d17ad569474b7167ed240f089cb204ebc892591e983e0d6e1d13be73677ad16747909b9a3fbffc768a61c1877d004517d73db
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/gotta/mod.rb
CHANGED
@@ -7,14 +7,14 @@ require "gotta/mod/project"
|
|
7
7
|
require "gotta/mod/event"
|
8
8
|
require "gotta/mod/listener"
|
9
9
|
require "gotta/mod/hub"
|
10
|
-
require "gotta/mod/
|
11
|
-
|
10
|
+
require "gotta/mod/mod_builder"
|
11
|
+
require 'pry'
|
12
12
|
module Gotta
|
13
13
|
module Mod
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
16
|
-
def self.hub=(
|
17
|
-
@@hub =
|
16
|
+
def self.hub=(hub_instance)
|
17
|
+
@@hub = hub_instance
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.hub
|
@@ -23,18 +23,18 @@ module Gotta
|
|
23
23
|
|
24
24
|
def self.now(dir: Dir.pwd)
|
25
25
|
project = Gotta::Project.new(dir)
|
26
|
-
Gotta::Project.config = project
|
26
|
+
Gotta::Project.config = project
|
27
27
|
listener = Listener.new(working_directory: dir)
|
28
28
|
self.hub = Hub.new(listener.queue)
|
29
29
|
hub_thread = Thread.new {hub.start} # Hub runs on a separate thread.
|
30
|
-
|
31
30
|
# Now require all `main.rb` files inside the mods folder
|
32
|
-
Dir.glob("#{project.
|
31
|
+
Dir.glob("#{project.mods_dir}/*") do |f|
|
33
32
|
rbfile = "#{f}/#{File.basename(f)}.rb"
|
34
|
-
|
33
|
+
ModBuilder.class_eval(File.read(rbfile), rbfile)
|
35
34
|
end
|
35
|
+
hub.check_dependencies
|
36
36
|
listener.start
|
37
|
-
puts "
|
37
|
+
puts "Ready for action."
|
38
38
|
sleep
|
39
39
|
end
|
40
40
|
end
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Dir.glob("#{__dir__}/*.rb").each {|f| require f}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Gotta
|
2
|
+
module Mod
|
3
|
+
module CLI
|
4
|
+
class Watch
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def run!
|
12
|
+
puts "Watch Received options #{@options}"
|
13
|
+
::Gotta::Mod.now
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
::Gotta::CLI::Command.register("watch", ::Gotta::Mod::CLI::Watch)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/gotta/mod/hub.rb
CHANGED
@@ -4,6 +4,13 @@ module Gotta
|
|
4
4
|
module Mod
|
5
5
|
require "set"
|
6
6
|
|
7
|
+
class MissingDependencyError < StandardError
|
8
|
+
def initialize(source, dep)
|
9
|
+
msg = "The mod '#{source}' depends on '#{dep}', but '#{dep}' is not installed in this project. Installed mods: #{Mod.hub.loaded_mods.to_a}"
|
10
|
+
super msg
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
# Starts a new thread and goes on a blocking
|
8
15
|
# operation to constantly pop values from the
|
9
16
|
# event queue.
|
@@ -13,7 +20,7 @@ module Gotta
|
|
13
20
|
# The execution of the mod code is done asynchronously
|
14
21
|
# on a separate thread.
|
15
22
|
class Hub
|
16
|
-
attr_reader :queue, :mods
|
23
|
+
attr_reader :queue, :mods, :loaded_mods
|
17
24
|
def initialize(queue)
|
18
25
|
# This is the separator to generate the key
|
19
26
|
# for the mods hash.
|
@@ -21,6 +28,7 @@ module Gotta
|
|
21
28
|
@queue = queue
|
22
29
|
@mutex = Mutex.new
|
23
30
|
@mods = {}
|
31
|
+
@loaded_mods = Set.new
|
24
32
|
@paths = Set.new
|
25
33
|
@threads = Set.new
|
26
34
|
end
|
@@ -51,6 +59,19 @@ module Gotta
|
|
51
59
|
}
|
52
60
|
end
|
53
61
|
|
62
|
+
def add_dependency(dep)
|
63
|
+
@dependencies ||= Set.new
|
64
|
+
@dependencies << dep
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_dependencies
|
68
|
+
@dependencies.each do |deps|
|
69
|
+
source, dep = deps.to_a[0]
|
70
|
+
next if @loaded_mods.include?(dep)
|
71
|
+
raise MissingDependencyError.new(source, dep)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
54
75
|
private
|
55
76
|
# Execute the mod code in a separate thread
|
56
77
|
def run_mods(event, keys)
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module Gotta
|
4
4
|
module Mod
|
5
|
-
class
|
5
|
+
class ModBuilder
|
6
6
|
|
7
|
-
def
|
7
|
+
def self.mod(name, &block)
|
8
8
|
new(name: name, &block)
|
9
9
|
end
|
10
10
|
|
@@ -15,7 +15,7 @@ module Gotta
|
|
15
15
|
def initialize(name:, &block)
|
16
16
|
@name = name
|
17
17
|
instance_eval(&block)
|
18
|
-
|
18
|
+
Mod.hub.loaded_mods << name
|
19
19
|
puts "Mod '#{name}' registered."
|
20
20
|
end
|
21
21
|
|
@@ -27,12 +27,12 @@ module Gotta
|
|
27
27
|
@description = desc
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
30
|
+
def depends_on(mod_name)
|
31
|
+
Mod.hub.add_dependency({self.name => mod_name})
|
32
32
|
end
|
33
33
|
|
34
34
|
def on(type, &block)
|
35
|
-
|
35
|
+
Mod.hub.register_mod(
|
36
36
|
mod_name: name,
|
37
37
|
path: @filter,
|
38
38
|
on: type,
|
data/lib/gotta/mod/project.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module Gotta
|
4
4
|
require "yaml"
|
5
|
-
|
5
|
+
require "ostruct"
|
6
|
+
class Project < OpenStruct
|
6
7
|
class << self
|
7
8
|
attr_accessor :config
|
8
9
|
end
|
@@ -12,16 +13,17 @@ module Gotta
|
|
12
13
|
@dir = dir
|
13
14
|
@config_file_path = "#{dir}/project.yml"
|
14
15
|
@config = read_config
|
15
|
-
@config["mods_dir"] ||= "mods"
|
16
|
-
@config["
|
17
|
-
@config["public_dir"] ||= "public"
|
16
|
+
@config["project"]["mods_dir"] ||= "mods"
|
17
|
+
@config["project"]["components_dir"] ||= @config["project"]["functions_dir"] || "components"
|
18
|
+
@config["project"]["public_dir"] ||= "public"
|
18
19
|
check_mods_dir
|
20
|
+
super(@config['project'])
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
25
|
def check_mods_dir
|
24
|
-
Dir.mkdir(@config["mods_dir"]) unless File.directory?(@config["mods_dir"])
|
26
|
+
Dir.mkdir(@config["project"]["mods_dir"]) unless File.directory?(@config["project"]["mods_dir"])
|
25
27
|
end
|
26
28
|
|
27
29
|
def read_config #=> {}
|
data/lib/gotta/mod/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotta-mod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
@@ -88,10 +88,11 @@ files:
|
|
88
88
|
- lib/gotta/mod.rb
|
89
89
|
- lib/gotta/mod/cli/commands.rb
|
90
90
|
- lib/gotta/mod/cli/new.rb
|
91
|
+
- lib/gotta/mod/cli/watch.rb
|
91
92
|
- lib/gotta/mod/event.rb
|
92
93
|
- lib/gotta/mod/hub.rb
|
93
94
|
- lib/gotta/mod/listener.rb
|
94
|
-
- lib/gotta/mod/
|
95
|
+
- lib/gotta/mod/mod_builder.rb
|
95
96
|
- lib/gotta/mod/monkey_patch.rb
|
96
97
|
- lib/gotta/mod/project.rb
|
97
98
|
- lib/gotta/mod/version.rb
|