alki-reload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81d6fa79f6cda460001792bc044bb0e249f2875a
4
+ data.tar.gz: 684d8997a8faf0aa288373adf5f2e94797e1cf7e
5
+ SHA512:
6
+ metadata.gz: 5f98c6a378a333915e1520e88e1d6253d02bf467f53a5b674b2d5791386b20de8b8ffe8cda59fe7ccb1659c53ca85cbb44d692a6c6a3f0d643732146028ac43d
7
+ data.tar.gz: c5bcbb7022610e6b1e27f1257c9b91d324cbe68b24a2c8cbcc95c19fb80fd9d43858b6b01d93346607d237b20b21e25df2b938cf8d427ecf068c82e216d043f2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -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 matt.edlefsen@gmail.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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alki-reload.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt Edlefsen
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,41 @@
1
+ # Alki::Reload
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/alki/reload`. 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 'alki-reload'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install alki-reload
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. 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/[USERNAME]/alki-reload. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ 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 'alki/reload/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alki-reload"
8
+ spec.version = Alki::Reload::VERSION
9
+ spec.authors = ["Matt Edlefsen"]
10
+ spec.email = ["matt.edlefsen@gmail.com"]
11
+
12
+ spec.summary = %q{Automatic reloading of alki projects}
13
+ spec.homepage = "https://github.com/alki-project/alki-reload"
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
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "listen", "~> 3.0"
26
+ spec.add_dependency "alki", "~> 0.9", ">= 0.9.1"
27
+ end
@@ -0,0 +1,75 @@
1
+ Alki do
2
+ func :reload do
3
+ root.assembly_instance.__reload__
4
+ end
5
+
6
+ set :watch, false
7
+
8
+ set :dirs do
9
+ ['lib']
10
+ end
11
+
12
+ set :whitelist do
13
+ []
14
+ end
15
+
16
+ set :watch_dirs do
17
+ handlers.inject([]) do |dirs,h|
18
+ dirs.push *h.dirs
19
+ end
20
+ end
21
+
22
+ service :handlers do
23
+ [dsl_handler,load_path_handler]
24
+ end
25
+
26
+ service :dsl_handler do
27
+ require 'alki/reload/dsl_handler'
28
+ Alki::Reload::DslHandler.new root_dir
29
+ end
30
+
31
+ service :load_path_handler do
32
+ require 'alki/reload/load_path_handler'
33
+ Alki::Reload::LoadPathHandler.new root_dir, dirs
34
+ end
35
+
36
+ factory :on_reload do
37
+ -> obj, method {
38
+ reloader.hooks << obj.method(method)
39
+ obj
40
+ }
41
+ end
42
+
43
+ service :reloader do
44
+ require 'alki/reload/reloader'
45
+ Alki::Reload::Reloader.new unloader
46
+ end
47
+
48
+ service :unloader do
49
+ require 'alki/reload/unloader'
50
+ Alki::Reload::Unloader.new handlers, whitelist
51
+ end
52
+
53
+ service :watcher do
54
+ require 'alki/reload/listen_watcher'
55
+ Alki::Reload::ListenWatcher.new assembly, watch_dirs
56
+ end
57
+
58
+ overlay :watcher, :on_reload, :stop!
59
+
60
+ overlay 'root.assembly_instance', :assembly_delegator
61
+
62
+ factory :assembly_delegator do
63
+ require 'alki/reload/assembly_delegator'
64
+ if watch
65
+ self.watcher.start!
66
+ end
67
+ -> obj {
68
+ Alki::Reload::AssemblyDelegator.new obj, reloader
69
+ }
70
+ end
71
+
72
+ set :root_dir do
73
+ File.expand_path('..',parent.config_dir)
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ require 'alki'
2
+
3
+ Alki.project_assembly!
@@ -0,0 +1,24 @@
1
+ require 'delegate'
2
+
3
+ module Alki
4
+ module Reload
5
+ class AssemblyDelegator < Delegator
6
+ def initialize(obj,reloader)
7
+ @obj = obj
8
+ @reloader = reloader
9
+ end
10
+
11
+ def __reload__
12
+ if @obj.respond_to? :__reload__
13
+ return false unless @obj.__reload__
14
+ end
15
+
16
+ @reloader.reload
17
+ end
18
+
19
+ def __getobj__
20
+ @obj
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ require 'alki/dsl/registry'
2
+
3
+ module Alki
4
+ module Reload
5
+ class DslHandler
6
+ def initialize(root_dir)
7
+ @root_dir = File.join(root_dir,'')
8
+ end
9
+
10
+ def handle_path(path)
11
+ dirs.each do |dir|
12
+ dir = File.join(dir,'')
13
+ if path.start_with? dir
14
+ entry = Alki::Dsl::Registry.lookup(path)
15
+ if entry && entry.data[:prefix] && entry.data[:name]
16
+ return [entry.data[:prefix], entry.data[:name]]
17
+ end
18
+ end
19
+ end
20
+ nil
21
+ end
22
+
23
+ def dirs
24
+ Alki::Dsl::Registry.registered_dirs.select do |d|
25
+ d.start_with?(@root_dir)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,73 @@
1
+ require 'listen'
2
+ require 'weakref'
3
+
4
+ module Alki
5
+ module Reload
6
+ class ListenWatcher
7
+ @listeners = {}
8
+
9
+ def initialize(reloader,dirs)
10
+ @reloader = reloader
11
+ @dirs = dirs
12
+ end
13
+
14
+ def start!
15
+ start_thread unless @thread
16
+ end
17
+
18
+ def stop!
19
+ if @thread && @thread != Thread.current
20
+ @queue.clear
21
+ @queue << :done
22
+ @thread.join
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def self.listener(dir,queue)
29
+ dir = File.join(dir,'')
30
+ unless @listeners[dir]
31
+ qs = []
32
+ @listeners[dir] = [qs,Listen.to(dir) do
33
+ qs.delete_if do |q|
34
+ begin
35
+ q << :reload
36
+ false
37
+ rescue WeakRef::RefError
38
+ true
39
+ end
40
+ end
41
+ end.tap{|l| l.start }]
42
+ end
43
+ @listeners[dir][0] << WeakRef.new(queue)
44
+ end
45
+
46
+ def start_thread
47
+ @queue = Queue.new
48
+ @thread = Thread.new do
49
+ @dirs.each{|dir| self.class.listener(dir,@queue) }
50
+ done = false
51
+ until done
52
+ begin
53
+ cmd = @queue.pop
54
+ if cmd == :done
55
+ done = true
56
+ elsif cmd == :reload
57
+ if @reloader.reload
58
+ done = true
59
+ end
60
+ end
61
+ rescue => e
62
+ $stderr.puts e
63
+ $stderr.puts e.backtrace.join("\n")
64
+ end
65
+ end
66
+ @queue.clear
67
+ @queue = nil
68
+ @thread = nil
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,20 @@
1
+ module Alki
2
+ module Reload
3
+ class LoadPathHandler
4
+ def initialize(root_dir,dirs)
5
+ @dirs = dirs.map{|d| File.join(root_dir,d,'')}.select{|d| Dir.exist? d }
6
+ end
7
+
8
+ attr_reader :dirs
9
+
10
+ def handle_path(path)
11
+ @dirs.each do |dir|
12
+ if path.start_with? dir
13
+ return path[dir.size..-1].match(%r{(?:(.*)/)?(.*).rb})[1..2]
14
+ end
15
+ end
16
+ nil
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Alki
2
+ module Reload
3
+ class Reloader
4
+ attr_reader :hooks
5
+
6
+ def initialize(unloader)
7
+ @unloader = unloader
8
+ @hooks = []
9
+ end
10
+
11
+ def reload
12
+ unloadable = @unloader.find_unloadable
13
+ if unloadable
14
+ hooks.each &:call
15
+ @unloader.unload unloadable
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ require 'alki/support'
2
+ require 'alki/dsl/registry'
3
+
4
+ module Alki
5
+ module Reload
6
+ class Unloader
7
+ def initialize(handlers,whitelist=[])
8
+ @handlers = handlers
9
+ @whitelist = whitelist
10
+ end
11
+
12
+ def find_unloadable
13
+ files = []
14
+ consts = []
15
+ $LOADED_FEATURES.each do |path|
16
+ if path.end_with?('.rb')
17
+ result = @handlers.lazy.map{|h| h.handle_path path }.find{|r| r != nil}
18
+ if result
19
+ add_const consts, *result
20
+ files << path
21
+ end
22
+ end
23
+ end
24
+ unless files.empty?
25
+ {files: files, consts: consts}
26
+ end
27
+ end
28
+
29
+ def unload(files:, consts:)
30
+ $LOADED_FEATURES.delete_if {|f| files.include? f}
31
+ consts.each {|(parent,const)| parent.send :remove_const, const}
32
+ end
33
+
34
+ private
35
+
36
+ def add_const(consts,parent,name)
37
+ unless whitelisted? parent, name
38
+ parent = parent ? Alki::Support.load_class(parent) : Object
39
+ name = Alki::Support.classify(name).to_sym
40
+ if parent && parent.is_a?(Module) && parent.const_defined?(name,false)
41
+ consts << [parent,name]
42
+ true
43
+ end
44
+ end
45
+ end
46
+
47
+ def whitelisted?(parent,name)
48
+ @whitelist.include?(parent ? File.join(parent,name) : name)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Alki
2
+ module Reload
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alki-reload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Edlefsen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-20 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: listen
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: alki
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.9.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.9'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.9.1
75
+ description:
76
+ email:
77
+ - matt.edlefsen@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - alki-reload.gemspec
89
+ - config/assembly.rb
90
+ - lib/alki/reload.rb
91
+ - lib/alki/reload/assembly_delegator.rb
92
+ - lib/alki/reload/dsl_handler.rb
93
+ - lib/alki/reload/listen_watcher.rb
94
+ - lib/alki/reload/load_path_handler.rb
95
+ - lib/alki/reload/reloader.rb
96
+ - lib/alki/reload/unloader.rb
97
+ - lib/alki/reload/version.rb
98
+ homepage: https://github.com/alki-project/alki-reload
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Automatic reloading of alki projects
122
+ test_files: []