gotta-mod 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dffbe2fab15b0bc117d98110717732176d932ada50899df7a733b3245d56e3eb
4
- data.tar.gz: 7c89416f876084ed357beeef168141caf75d350a274b0f50d5af031b844d369d
3
+ metadata.gz: cddb21ae617ea4908ec5074b0f284a65a92847d2c973c47f4cac7d1e42671994
4
+ data.tar.gz: d01212517c946a46de68764f60baa90636bdb050ffe36b03c396bcba0e879b56
5
5
  SHA512:
6
- metadata.gz: 8901b3e156889aeabb0a0edde0cc43716efb835dac67897bf0f5bd4dd50624d954dbdde628ef9f8bd02d4d373cfbb2f854dafa9e2a00864e339c7c2cd5d7f0ef
7
- data.tar.gz: 1736f17e8d5357f25ce2d4fcbb6cc9f6231f57c426a453c4a707c19e9fbf2816c069c8c4bce7d975cbf7ab1c2bdc39e7c4a490c7616a1da157ea7fcb9c51c2e5
6
+ metadata.gz: 72c57e501a57bb5a9690ab03e518c9fe7b29f3b4300810f77058a9e2a77a5b87bada1c8bfc1eeb11d752b9d7726ca65266af20600574fb773c018e0a7b71b52b
7
+ data.tar.gz: b95c7bb86fa24111b2331c26f60d17ad569474b7167ed240f089cb204ebc892591e983e0d6e1d13be73677ad16747909b9a3fbffc768a61c1877d004517d73db
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gotta-mod (0.1.1)
4
+ gotta-mod (0.1.2)
5
5
  listen (~> 3.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -3,8 +3,3 @@
3
3
  Description will follow
4
4
 
5
5
  # Developing
6
-
7
- * Clone the repo.
8
- * Run `./dev-setup.sh`
9
- * Create a gotta project: `gotta new project test-proj`
10
- * Cd into the project folder and run `gotta mod`
@@ -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/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=(hub)
17
- @@hub = 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.config
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.config["mods_dir"]}/*") do |f|
31
+ Dir.glob("#{project.mods_dir}/*") do |f|
33
32
  rbfile = "#{f}/#{File.basename(f)}.rb"
34
- Mod.class_eval(File.read(rbfile), rbfile)
33
+ ModBuilder.class_eval(File.read(rbfile), rbfile)
35
34
  end
35
+ hub.check_dependencies
36
36
  listener.start
37
- puts "Gotta start using it now."
37
+ puts "Ready for action."
38
38
  sleep
39
39
  end
40
40
  end
@@ -1 +1 @@
1
- require_relative "new"
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
@@ -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 Mod
5
+ class ModBuilder
6
6
 
7
- def build(name, &block)
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
- @hub = Mod.hub
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 project
31
- Gotta::Project.config
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
- @hub.register_mod(
35
+ Mod.hub.register_mod(
36
36
  mod_name: name,
37
37
  path: @filter,
38
38
  on: type,
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Gotta
4
4
  require "yaml"
5
- class Project
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["functions_dir"] ||= "functions"
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 #=> {}
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gotta
4
4
  module Mod
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
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.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/mod.rb
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