Class: Droonga::CatalogObserver
- Inherits:
-
Object
- Object
- Droonga::CatalogObserver
- Defined in:
- lib/droonga/catalog_observer.rb
Constant Summary collapse
- DEFAULT_CATALOG_PATH =
"catalog.json"- CHECK_INTERVAL =
1
Instance Method Summary collapse
- #catalog_path ⇒ Object
- #catalog_updated? ⇒ Boolean
- #ensure_latest_catalog_loaded ⇒ Object
-
#initialize(loop) ⇒ CatalogObserver
constructor
A new instance of CatalogObserver.
- #load_catalog ⇒ Object
Constructor Details
#initialize(loop) ⇒ CatalogObserver
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/droonga/catalog_observer.rb', line 23 def initialize(loop) @catalog_path = catalog_path load_catalog watcher = Cool.io::TimerWatcher.new(CHECK_INTERVAL, true) observer = self watcher.on_timer do observer.ensure_latest_catalog_loaded end loop.attach(watcher) end |
Instance Method Details
#catalog_path ⇒ Object
41 42 43 44 |
# File 'lib/droonga/catalog_observer.rb', line 41 def catalog_path path = ENV["DROONGA_CATALOG"] || DEFAULT_CATALOG_PATH File.(path) end |
#catalog_updated? ⇒ Boolean
46 47 48 |
# File 'lib/droonga/catalog_observer.rb', line 46 def catalog_updated? File.mtime(catalog_path) > @catalog_mtime end |
#ensure_latest_catalog_loaded ⇒ Object
35 36 37 38 39 |
# File 'lib/droonga/catalog_observer.rb', line 35 def ensure_latest_catalog_loaded if catalog_updated? load_catalog end end |
#load_catalog ⇒ Object
50 51 52 53 54 55 |
# File 'lib/droonga/catalog_observer.rb', line 50 def load_catalog loader = CatalogLoader.new(@catalog_path) Droonga.catalog = loader.load @catalog_mtime = File.mtime(@catalog_path) $log.info "catalog loaded", path: @catalog_path, mtime: @catalog_mtime end |