Module: Uses
- Defined in:
- lib/uses.rb,
lib/uses/error.rb,
lib/uses/config.rb,
lib/uses/method.rb,
lib/uses/version.rb,
lib/uses/initializer.rb,
lib/uses/method_name.rb,
lib/uses/inject_double.rb,
lib/uses/uses_method_args.rb,
lib/uses/invalid_method_name.rb,
lib/uses/circular_dependency/error.rb,
lib/uses/circular_dependency/analyzer.rb,
lib/uses/initializer/base_initializer.rb,
lib/uses/circular_dependency/log_notifier.rb,
lib/uses/circular_dependency/base_notifier.rb,
lib/uses/circular_dependency/ignore_notifier.rb,
lib/uses/circular_dependency/raise_error_notifier.rb
Defined Under Namespace
Modules: CircularDependency, Initializer, InjectDouble, Method Classes: Config, Error, InvalidMethodName, MethodName, UsesMethodArgs
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.config {|@@config| ... } ⇒ Object
Yields the Uses::Config instance governing this gem’s behavior.
-
.initializers {|config.initializers| ... } ⇒ Object
Yields a hash of initializer, with the intention that you insert the initializer for your service into this hash.
Class Method Details
.config {|@@config| ... } ⇒ Object
Yields the Uses::Config instance governing this gem’s behavior. You should call this in an intializer. See Uses::Config for what options exist
41 42 43 44 45 |
# File 'lib/uses.rb', line 41 def self.config @@config ||= Uses::Config.new yield(@@config) if block_given? @@config end |
.initializers {|config.initializers| ... } ⇒ Object
Yields a hash of initializer, with the intention that you insert the initializer for your service into this hash. The key should be the class name that would be given to a ‘uses` invocation, and the value should be a proc that returns an instance of that class.
The reason you would do this is if your service requires special setup beyond calling new without arguments. For example:
require "uses"
Uses.initializers do |initializers|
initializers[Aws::S3::Client] = ->(*) {
Aws::S3::Client.new(
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
region: ENV["AWS_REGION"],
)
}
end
# Then, in a service that uses this:
class MyService
include Uses::Method
uses Aws::S3::Client, as: :s3, initialize: :config_initializers
def some_method
s3.whatever # s3 has been initialized using the Proc above
end
end
33 34 35 36 |
# File 'lib/uses.rb', line 33 def self.initializers yield(config.initializers) if block_given? config.initializers end |