Class: CubaApi::Rack::Reloader
- Inherits:
-
Object
- Object
- CubaApi::Rack::Reloader
- Defined in:
- lib/cuba_api/rack/reloader_rack.rb
Class Method Summary collapse
- .doit(basedir, baseconstant) ⇒ Object
- .maybe_remove_constant(f, basedir, baseconstant) ⇒ Object
- .parse(basedir, baseconstant) ⇒ Object
Class Method Details
.doit(basedir, baseconstant) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cuba_api/rack/reloader_rack.rb', line 27 def self.doit( basedir, baseconstant ) if @max_last_modified parse( basedir, baseconstant ) do |f| maybe_remove_constant( f, basedir, baseconstant ) puts "[CubaAPI::Reloader] #{f}: #{load f}" end else parse( basedir, baseconstant ) {} end end |
.maybe_remove_constant(f, basedir, baseconstant) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cuba_api/rack/reloader_rack.rb', line 15 def self.maybe_remove_constant( f, basedir, baseconstant ) c = baseconstant cname = nil f.sub( /#{basedir}/, '' ).split( /\/|\./ ).each do |name| if name != 'rb' ( c = c.const_get( cname ) ) rescue nil cname = name.split('_').each { |a| a.capitalize! }.join.to_sym end end c.send( :remove_const, cname ) rescue nil end |
.parse(basedir, baseconstant) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/cuba_api/rack/reloader_rack.rb', line 5 def self.parse( basedir, baseconstant ) Dir[ File.join( basedir, '**', '*.rb' ) ].each do |f| last_modified = File.mtime( f ).to_f if ! File.directory?( f ) && last_modified > @max_last_modified.to_f @max_last_modified = last_modified yield f end end end |