Class: Persistable::Factory Deprecated
- Inherits:
-
Object
- Object
- Persistable::Factory
- Defined in:
- lib/persistable/factory.rb
Overview
Deprecated.
This class has a strange API, so in the future a new API will be provided
Factory class to help to define particular adapters.
Class Method Summary collapse
-
.build(yml_file_path, defaults = {}) ⇒ Adapter
Builds a new adapter.
-
.load_yml(yml_file_path, defaults = {}) ⇒ Hash
Loads the config from a yml file and returns the values as a ‘Hash`.
Class Method Details
.build(yml_file_path, defaults = {}) ⇒ Adapter
Builds a new adapter
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/persistable/factory.rb', line 17 def self.build(yml_file_path, defaults = {}) adapter_config = load_yml(yml_file_path, defaults) raise ArgumentError.new("Invalid Parameter: There should be a Hash with :adapter key.") unless adapter_config[:adapter] adapter_config = adapter_config[:adapter].symbolize_keys raise ArgumentError.new("Invalid Parameter: There should be a Hash with :type key.") unless adapter_config[:type] adapter = case adapter_config.delete(:type) when 'filesystem' require "persistable/fs_adapter" Persistable::FSAdapter.new(adapter_config) when 'mogilefs' require "persistable/mogile_fs_adapter" Persistable::MogileFSAdapter.new(adapter_config) when 'memory' require "persistable/memory_adapter" Persistable::MemoryAdapter.new(adapter_config) when 'cloud' require "persistable/cloud_storage_adapter" Persistable::CloudStorageAdapter.new(adapter_config) end return adapter end |
.load_yml(yml_file_path, defaults = {}) ⇒ Hash
Loads the config from a yml file and returns the values as a ‘Hash`
46 47 48 49 |
# File 'lib/persistable/factory.rb', line 46 def self.load_yml(yml_file_path, defaults = {}) defaults.merge!(YAML.load_file(yml_file_path).symbolize_keys) if yml_file_path && File.exists?(yml_file_path) return defaults end |