Class: TG::Geometry::Registry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tg/geometry/registry.rb

Constant Summary collapse

DEFAULT_INDEX_OPTIONS =
{
  via: :geojson,
  strategy: :rtree,
  predicate: :covers,
  geometry_index: :ystripes
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: nil, source: nil, **index_options) ⇒ Registry

Returns a new instance of Registry.



36
37
38
39
40
41
42
# File 'lib/tg/geometry/registry.rb', line 36

def initialize(entries: nil, source: nil, **index_options)
  @entries = entries
  @source = source
  @index_options = self.class.index_options.merge(index_options).freeze
  @reload_mutex = Mutex.new
  @index = nil
end

Instance Attribute Details

#index_optionsObject (readonly)

Returns the value of attribute index_options.



31
32
33
# File 'lib/tg/geometry/registry.rb', line 31

def index_options
  @index_options
end

Class Method Details

.index_options(**options) ⇒ Object



23
24
25
26
27
28
# File 'lib/tg/geometry/registry.rb', line 23

def index_options(**options)
  inherited = superclass.respond_to?(:index_options) ? superclass.index_options : DEFAULT_INDEX_OPTIONS
  return inherited.merge(@index_options || {}).freeze if options.empty?

  @index_options = inherited.merge(@index_options || {}, options).freeze
end

.source(&block) ⇒ Object



18
19
20
21
# File 'lib/tg/geometry/registry.rb', line 18

def source(&block)
  @source = block if block
  @source || (superclass.source if superclass.respond_to?(:source))
end

Instance Method Details

#indexObject



50
51
52
# File 'lib/tg/geometry/registry.rb', line 50

def index
  @index || raise(TG::Geometry::Error, "registry index is not loaded; call reload! first")
end

#loaded?Boolean

Returns:

  • (Boolean)


54
# File 'lib/tg/geometry/registry.rb', line 54

def loaded? = !@index.nil?

#reload!Object



44
45
46
47
48
# File 'lib/tg/geometry/registry.rb', line 44

def reload!
  new_index = TG::Geometry::Index.build(resolve_entries, **@index_options)
  @reload_mutex.synchronize { @index = new_index }
  new_index
end