Class: Rosette::Core::Configurator
- Inherits:
-
Object
- Object
- Rosette::Core::Configurator
- Includes:
- Integrations::Integratable
- Defined in:
- lib/rosette/core/configurator.rb
Overview
Builds Rosette configuration. Usually used via Rosette#build_config.
Instance Attribute Summary collapse
-
#cache ⇒ #fetch
readonly
The cache instance to use (can be
nil). -
#datastore ⇒ DataStore
readonly
The datastore to store phrases and translations in.
-
#error_reporter ⇒ ErrorReporter
readonly
The error reporter to use if errors occur.
-
#queue ⇒ Rosette::Queuing::Queue
readonly
The queue implementation to use.
-
#repo_configs ⇒ Array<RepoConfig>
readonly
The current array of configured repo configs.
Instance Method Summary collapse
-
#add_repo(name) ⇒ void
Adds a repo config.
-
#get_repo(name) ⇒ RepoConfig
Retrieve a repo config by name.
-
#initialize ⇒ Configurator
constructor
Creates a new config object.
-
#use_cache(*args) ⇒ void
Set the cache implementation.
-
#use_datastore(datastore, options = {}) ⇒ void
Set the datastore to use to store phrases and translations.
-
#use_error_reporter(reporter) ⇒ void
Set the error reporter this config should use to report errors.
-
#use_queue(queue) {|configurator| ... } ⇒ void
Set the queue implementation.
Methods included from Integrations::Integratable
#add_integration, #apply_integrations, #get_integration, #integrations
Constructor Details
#initialize ⇒ Configurator
Creates a new config object.
37 38 39 40 41 42 |
# File 'lib/rosette/core/configurator.rb', line 37 def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end |
Instance Attribute Details
#cache ⇒ #fetch (readonly)
Returns The cache instance to use (can be nil).
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rosette/core/configurator.rb', line 31 class Configurator include Integrations::Integratable attr_reader :repo_configs, :datastore, :cache, :queue, :error_reporter # Creates a new config object. def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end # Adds a repo config. # # @param [String] name The semantic name of the repo. # @return [void] def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end # Retrieve a repo config by name. # # @param [String] name The semantic name of the repo to retrieve. # @return [RepoConfig] def get_repo(name) repo_configs.find { |rc| rc.name == name } end # Set the datastore to use to store phrases and translations. # # @param [Const, String] datastore The datastore to use. When this # parameter is a string, +use_datastore+ will try to look up the # corresponding constant with a "DataStore" suffix. If it's a constant # instead, the constant is used without modifications. # @param [Hash] options A hash of options passed to the datastore's # constructor. # @return [void] def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end # Set the error reporter this config should use to report errors. The # default error reporter is an instance of {PrintingErrorReporter}. # # @param [ErrorReporter] reporter The error reporter. # @return [void] def use_error_reporter(reporter) @error_reporter = reporter end # Set the cache implementation. This must be one of the offerings in # +ActiveSupport::Cache+: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @param [*] args The args to pass to ActiveSupport::Cache#lookup_store: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store # @return [void] def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end # Set the queue implementation. Queues must implement the # [Rosette::Queuing::Queue] interface. # # @param [Const, String] queue The queue to use. When this parameter # is a string, +use_queue+ will try to look up the corresponding # constant with a "Queue" suffix. If it's a constant instead, the # constant is used without modifications. # @param [Hash] options A hash of options passed to the queue's # constructor. # @return [void] def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end private def find_datastore_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}DataStore" if Rosette::DataStores.const_defined?(const_str) Rosette::DataStores.const_get(const_str) end end def find_queue_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}Queue" if Rosette::Queuing.const_defined?(const_str) Rosette::Queuing.const_get(const_str)::Queue end end end |
#datastore ⇒ DataStore (readonly)
Returns The datastore to store phrases and translations in.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rosette/core/configurator.rb', line 31 class Configurator include Integrations::Integratable attr_reader :repo_configs, :datastore, :cache, :queue, :error_reporter # Creates a new config object. def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end # Adds a repo config. # # @param [String] name The semantic name of the repo. # @return [void] def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end # Retrieve a repo config by name. # # @param [String] name The semantic name of the repo to retrieve. # @return [RepoConfig] def get_repo(name) repo_configs.find { |rc| rc.name == name } end # Set the datastore to use to store phrases and translations. # # @param [Const, String] datastore The datastore to use. When this # parameter is a string, +use_datastore+ will try to look up the # corresponding constant with a "DataStore" suffix. If it's a constant # instead, the constant is used without modifications. # @param [Hash] options A hash of options passed to the datastore's # constructor. # @return [void] def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end # Set the error reporter this config should use to report errors. The # default error reporter is an instance of {PrintingErrorReporter}. # # @param [ErrorReporter] reporter The error reporter. # @return [void] def use_error_reporter(reporter) @error_reporter = reporter end # Set the cache implementation. This must be one of the offerings in # +ActiveSupport::Cache+: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @param [*] args The args to pass to ActiveSupport::Cache#lookup_store: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store # @return [void] def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end # Set the queue implementation. Queues must implement the # [Rosette::Queuing::Queue] interface. # # @param [Const, String] queue The queue to use. When this parameter # is a string, +use_queue+ will try to look up the corresponding # constant with a "Queue" suffix. If it's a constant instead, the # constant is used without modifications. # @param [Hash] options A hash of options passed to the queue's # constructor. # @return [void] def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end private def find_datastore_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}DataStore" if Rosette::DataStores.const_defined?(const_str) Rosette::DataStores.const_get(const_str) end end def find_queue_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}Queue" if Rosette::Queuing.const_defined?(const_str) Rosette::Queuing.const_get(const_str)::Queue end end end |
#error_reporter ⇒ ErrorReporter (readonly)
Returns The error reporter to use if errors occur.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rosette/core/configurator.rb', line 31 class Configurator include Integrations::Integratable attr_reader :repo_configs, :datastore, :cache, :queue, :error_reporter # Creates a new config object. def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end # Adds a repo config. # # @param [String] name The semantic name of the repo. # @return [void] def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end # Retrieve a repo config by name. # # @param [String] name The semantic name of the repo to retrieve. # @return [RepoConfig] def get_repo(name) repo_configs.find { |rc| rc.name == name } end # Set the datastore to use to store phrases and translations. # # @param [Const, String] datastore The datastore to use. When this # parameter is a string, +use_datastore+ will try to look up the # corresponding constant with a "DataStore" suffix. If it's a constant # instead, the constant is used without modifications. # @param [Hash] options A hash of options passed to the datastore's # constructor. # @return [void] def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end # Set the error reporter this config should use to report errors. The # default error reporter is an instance of {PrintingErrorReporter}. # # @param [ErrorReporter] reporter The error reporter. # @return [void] def use_error_reporter(reporter) @error_reporter = reporter end # Set the cache implementation. This must be one of the offerings in # +ActiveSupport::Cache+: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @param [*] args The args to pass to ActiveSupport::Cache#lookup_store: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store # @return [void] def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end # Set the queue implementation. Queues must implement the # [Rosette::Queuing::Queue] interface. # # @param [Const, String] queue The queue to use. When this parameter # is a string, +use_queue+ will try to look up the corresponding # constant with a "Queue" suffix. If it's a constant instead, the # constant is used without modifications. # @param [Hash] options A hash of options passed to the queue's # constructor. # @return [void] def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end private def find_datastore_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}DataStore" if Rosette::DataStores.const_defined?(const_str) Rosette::DataStores.const_get(const_str) end end def find_queue_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}Queue" if Rosette::Queuing.const_defined?(const_str) Rosette::Queuing.const_get(const_str)::Queue end end end |
#queue ⇒ Rosette::Queuing::Queue (readonly)
Returns The queue implementation to use.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rosette/core/configurator.rb', line 31 class Configurator include Integrations::Integratable attr_reader :repo_configs, :datastore, :cache, :queue, :error_reporter # Creates a new config object. def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end # Adds a repo config. # # @param [String] name The semantic name of the repo. # @return [void] def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end # Retrieve a repo config by name. # # @param [String] name The semantic name of the repo to retrieve. # @return [RepoConfig] def get_repo(name) repo_configs.find { |rc| rc.name == name } end # Set the datastore to use to store phrases and translations. # # @param [Const, String] datastore The datastore to use. When this # parameter is a string, +use_datastore+ will try to look up the # corresponding constant with a "DataStore" suffix. If it's a constant # instead, the constant is used without modifications. # @param [Hash] options A hash of options passed to the datastore's # constructor. # @return [void] def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end # Set the error reporter this config should use to report errors. The # default error reporter is an instance of {PrintingErrorReporter}. # # @param [ErrorReporter] reporter The error reporter. # @return [void] def use_error_reporter(reporter) @error_reporter = reporter end # Set the cache implementation. This must be one of the offerings in # +ActiveSupport::Cache+: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @param [*] args The args to pass to ActiveSupport::Cache#lookup_store: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store # @return [void] def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end # Set the queue implementation. Queues must implement the # [Rosette::Queuing::Queue] interface. # # @param [Const, String] queue The queue to use. When this parameter # is a string, +use_queue+ will try to look up the corresponding # constant with a "Queue" suffix. If it's a constant instead, the # constant is used without modifications. # @param [Hash] options A hash of options passed to the queue's # constructor. # @return [void] def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end private def find_datastore_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}DataStore" if Rosette::DataStores.const_defined?(const_str) Rosette::DataStores.const_get(const_str) end end def find_queue_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}Queue" if Rosette::Queuing.const_defined?(const_str) Rosette::Queuing.const_get(const_str)::Queue end end end |
#repo_configs ⇒ Array<RepoConfig> (readonly)
Returns The current array of configured repo configs.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rosette/core/configurator.rb', line 31 class Configurator include Integrations::Integratable attr_reader :repo_configs, :datastore, :cache, :queue, :error_reporter # Creates a new config object. def initialize @repo_configs = [] @integrations = [] @cache = ActiveSupport::Cache.lookup_store @error_reporter ||= PrintingErrorReporter.new(STDOUT) end # Adds a repo config. # # @param [String] name The semantic name of the repo. # @return [void] def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end # Retrieve a repo config by name. # # @param [String] name The semantic name of the repo to retrieve. # @return [RepoConfig] def get_repo(name) repo_configs.find { |rc| rc.name == name } end # Set the datastore to use to store phrases and translations. # # @param [Const, String] datastore The datastore to use. When this # parameter is a string, +use_datastore+ will try to look up the # corresponding constant with a "DataStore" suffix. If it's a constant # instead, the constant is used without modifications. # @param [Hash] options A hash of options passed to the datastore's # constructor. # @return [void] def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end # Set the error reporter this config should use to report errors. The # default error reporter is an instance of {PrintingErrorReporter}. # # @param [ErrorReporter] reporter The error reporter. # @return [void] def use_error_reporter(reporter) @error_reporter = reporter end # Set the cache implementation. This must be one of the offerings in # +ActiveSupport::Cache+: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html # # @param [*] args The args to pass to ActiveSupport::Cache#lookup_store: # http://api.rubyonrails.org/classes/ActiveSupport/Cache.html#method-c-lookup_store # @return [void] def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end # Set the queue implementation. Queues must implement the # [Rosette::Queuing::Queue] interface. # # @param [Const, String] queue The queue to use. When this parameter # is a string, +use_queue+ will try to look up the corresponding # constant with a "Queue" suffix. If it's a constant instead, the # constant is used without modifications. # @param [Hash] options A hash of options passed to the queue's # constructor. # @return [void] def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end private def find_datastore_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}DataStore" if Rosette::DataStores.const_defined?(const_str) Rosette::DataStores.const_get(const_str) end end def find_queue_const(name) const_str = "#{Rosette::Core::StringUtils.camelize(name)}Queue" if Rosette::Queuing.const_defined?(const_str) Rosette::Queuing.const_get(const_str)::Queue end end end |
Instance Method Details
#add_repo(name) ⇒ void
This method returns an undefined value.
Adds a repo config.
48 49 50 51 52 53 |
# File 'lib/rosette/core/configurator.rb', line 48 def add_repo(name) repo_configs << Rosette::Core::RepoConfig.new(name, self).tap do |repo_config| yield repo_config repo_config.apply_integrations(repo_config) end end |
#get_repo(name) ⇒ RepoConfig
Retrieve a repo config by name.
59 60 61 |
# File 'lib/rosette/core/configurator.rb', line 59 def get_repo(name) repo_configs.find { |rc| rc.name == name } end |
#use_cache(*args) ⇒ void
This method returns an undefined value.
Set the cache implementation. This must be one of the offerings in ActiveSupport::Cache: api.rubyonrails.org/classes/ActiveSupport/Cache.html
106 107 108 |
# File 'lib/rosette/core/configurator.rb', line 106 def use_cache(*args) @cache = ActiveSupport::Cache.lookup_store(args) end |
#use_datastore(datastore, options = {}) ⇒ void
This method returns an undefined value.
Set the datastore to use to store phrases and translations.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rosette/core/configurator.rb', line 72 def use_datastore(datastore, = {}) const = case datastore when String if const = find_datastore_const(datastore) const else raise ArgumentError, "'#{datastore}' couldn't be found." end when Class datastore else raise ArgumentError, "'#{datastore}' must be a String or Class." end @datastore = const.new() nil end |
#use_error_reporter(reporter) ⇒ void
This method returns an undefined value.
Set the error reporter this config should use to report errors. The default error reporter is an instance of PrintingErrorReporter.
95 96 97 |
# File 'lib/rosette/core/configurator.rb', line 95 def use_error_reporter(reporter) @error_reporter = reporter end |
#use_queue(queue) {|configurator| ... } ⇒ void
This method returns an undefined value.
Set the queue implementation. Queues must implement the
- Rosette::Queuing::Queue
-
interface.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rosette/core/configurator.rb', line 120 def use_queue(queue) const = case queue when String if const = find_queue_const(queue) const else raise ArgumentError, "'#{queue}' couldn't be found." end when Class queue else raise ArgumentError, "'#{queue}' must be a String or Class." end configurator = Rosette::Queuing::QueueConfigurator.new yield configurator if block_given? @queue = const.new(configurator) nil end |