Module: Serviced
- Defined in:
- lib/serviced.rb,
lib/serviced/flow.rb,
lib/serviced/query.rb,
lib/serviced/typed.rb,
lib/serviced/errors.rb,
lib/serviced/result.rb,
lib/serviced/service.rb,
lib/serviced/version.rb,
lib/serviced/configuration.rb,
lib/serviced/result_helpers.rb
Overview
Defined Under Namespace
Modules: ResultHelpers, Typed Classes: Configuration, Error, Failure, Flow, InvalidQuery, InvalidResultAccess, MissingTransactionHandler, Query, Result, ResultTypeError, Rollback, Service, Success
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.configuration ⇒ Serviced::Configuration
The current configuration.
-
.configure {|config| ... } ⇒ Object
Yields the configuration for mutation.
-
.error_summary(errors) ⇒ String
Renders an ActiveModel::Errors into a short human string.
-
.reset_configuration! ⇒ Serviced::Configuration
Resets configuration to defaults.
-
.snapshot(value) ⇒ Object
Returns an immutable snapshot of a value-like input.
Class Method Details
.configuration ⇒ Serviced::Configuration
Returns the current configuration.
23 24 25 |
# File 'lib/serviced.rb', line 23 def configuration @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
Yields the configuration for mutation.
29 30 31 |
# File 'lib/serviced.rb', line 29 def configure yield(configuration) end |
.error_summary(errors) ⇒ String
Renders an ActiveModel::Errors into a short human string. Falls back to the attribute names when full messages cannot be built: an anonymous class has no model_name, which ActiveModel needs to humanize messages. Building an error message must never itself raise.
45 46 47 48 49 |
# File 'lib/serviced.rb', line 45 def error_summary(errors) errors..join(", ") rescue StandardError errors.attribute_names.join(", ") end |
.reset_configuration! ⇒ Serviced::Configuration
Resets configuration to defaults. Primarily useful in test suites.
35 36 37 |
# File 'lib/serviced.rb', line 35 def reset_configuration! @configuration = Configuration.new end |
.snapshot(value) ⇒ Object
Returns an immutable snapshot of a value-like input. Arrays, hashes, sets and strings are deep-copied and frozen, so the result is isolated from the caller and cannot be mutated. Objects with identity (ActiveRecord records and other non-data objects) are returned by reference, unfrozen: a deep copy of a record is a different, non-persisted object, and freezing one in place would corrupt the caller's copy. Scalars are already immutable.
59 60 61 62 63 64 65 66 67 |
# File 'lib/serviced.rb', line 59 def snapshot(value) case value when Array then value.map { |element| snapshot(element) }.freeze when Set then Set.new(value.map { |element| snapshot(element) }).freeze when Hash then snapshot_hash(value) when String then snapshot_string(value) else value end end |