Last active
September 16, 2017 15:58
-
-
Save unau/94efd42bed93f31c1ec50491b168adf0 to your computer and use it in GitHub Desktop.
自分は SketchUp の Ruby コンソールで使うんだけど、開発中にいろいろスクリプトをいじったとして、Ruby コンソールで Matome.clap とやると更新のあったファイルだけリロードしてくれるようなもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Matome | |
@@clapLoader = nil | |
def self.clap(dir=nil) | |
if @@clapLoader then | |
@@clapLoader.reload | |
else | |
@@clapLoader = ClapLoader.new dir | |
end | |
end | |
class ClapLoader | |
def initialize(dir) | |
@own = __FILE__ | |
@dir = dir.split('/')[0..-2].join('/') | |
@mtimes = {} | |
reload | |
end | |
def reload | |
$LOADED_FEATURES.each{|f| | |
if f != @own && f.start_with?(@dir) then | |
File::Stat.new(f).mtime.tap { |mtimeOnFS| | |
@mtimes[f].tap { |mtimeOnCache| | |
if ! mtimeOnCache then | |
@mtimes[f] = mtimeOnFS | |
elsif mtimeOnFS > mtimeOnCache then | |
warn("LOADING: %s" % f) | |
load f | |
@mtimes[f] = File::Stat.new(f).mtime | |
end | |
} | |
} rescue warn('skip ... %s' % f) | |
end | |
} | |
end | |
end | |
end | |
__END__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matome/clap-loader' | |
require 'matome/something-great' | |
Matome.clap __FILE__ | |
Matome.SomethingGreat | |
Matome.clap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment