Class: RGeo::ActiveRecord::RGeoFactorySettings

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/active_record/ar_factory_settings.rb

Overview

An object that manages the RGeo factories for a ConnectionPool.

Constant Summary collapse

DEFAULT =
self.new

Instance Method Summary collapse

Constructor Details

#initializeRGeoFactorySettings

:nodoc:



16
17
18
19
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 16

def initialize  # :nodoc:
  @factory_generators = {}
  @column_factories = {}
end

Instance Method Details

#clear!(table_name_ = nil) ⇒ Object

Clear settings for the given table name, or for all tables



51
52
53
54
55
56
57
58
59
60
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 51

def clear!(table_name_=nil)
  if table_name_
    table_name_ = table_name_.to_s
    @factory_generators.delete(table_name_)
    @column_factories.delete(table_name_)
  else
    @factory_generators.clear
    @column_factories.clear
  end
end

#get_column_factory(table_name_, column_name_, params_ = nil) ⇒ Object

Get the factory or factory generator for the given table name and column name.



33
34
35
36
37
38
39
40
41
42
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 33

def get_column_factory(table_name_, column_name_, params_=nil)
  table_name_ = table_name_.to_s
  column_name_ = column_name_.to_s
  result_ = (@column_factories[table_name_] ||= {})[column_name_] ||
    @factory_generators[table_name_] || ::RGeo::ActiveRecord::DEFAULT_FACTORY_GENERATOR
  if params_ && !result_.kind_of?(::RGeo::Feature::Factory::Instance)
    result_ = result_.call(params_)
  end
  result_
end

#get_factory_generator(table_name_) ⇒ Object

Get the default factory generator for the given table



22
23
24
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 22

def get_factory_generator(table_name_)
  @factory_generators[table_name_.to_s] || ::RGeo::ActiveRecord::DEFAULT_FACTORY_GENERATOR
end

#set_column_factory(table_name_, column_name_, factory_) ⇒ Object

Set the factory or factory generator for the given table name and column name.



46
47
48
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 46

def set_column_factory(table_name_, column_name_, factory_)
  (@column_factories[table_name_.to_s] ||= {})[column_name_.to_s] = factory_
end

#set_factory_generator(table_name_, gen_) ⇒ Object

Set the default factory generator for the given table



27
28
29
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 27

def set_factory_generator(table_name_, gen_)
  @factory_generators[table_name_.to_s] = gen_
end