Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

The "Signs And Portents" Update

Added `Cuprum.initializer` to initialize dependencies and error messages. Call `Cuprum.initializer.call` in the entry point or initializers of your application to avoid missing error messages.

### Results

Added `Result.success` and `Result.failure`, which provide singleton results with respective `:success` and `:failure` statuses.
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end
group :docs do
gem 'jekyll', '~> 4.3'
gem 'jekyll-theme-dinky', '~> 0.2'
gem 'logger', '~> 1.7'

# Use Kramdown to parse GFM-dialect Markdown.
gem 'kramdown-parser-gfm', '~> 1.1'
Expand Down
2 changes: 1 addition & 1 deletion docs/_constants/cuprum/error/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ short_description: Short string used to identify the type of error.
value: "'cuprum.error'"
data_path: cuprum/error/type
description: |-
Primarily used for serialization. This value can be overriden by passing
Primarily used for serialization. This value can be overridden by passing
in the :type parameter to the constructor.

Subclasses of Cuprum::Error should define their own default TYPE constant.
Expand Down
14 changes: 14 additions & 0 deletions docs/_methods/cuprum/c-initializer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Cuprum.initializer
parent_path: cuprum
signature: initializer
slug: initializer
constructor: false
data_path: cuprum/c-initializer
returns:
- description: |-
the initializer
for the module.
type:
- name: SleepingKingStudios::Tools::Toolbox::Initializer
version: "*"
6 changes: 3 additions & 3 deletions docs/_methods/cuprum/error/i-as-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ constructor: false
data_path: cuprum/error/i-as-json
description: |-
By default, contains the #type and #message properties and an empty :data
Hash. This can be overriden in subclasses by overriding the private method
#as_json_data; this should always return a Hash with String keys and whose
values are basic objects or data structures of the same.
Hash. This can be overridden in subclasses by overriding the private
method #as_json_data; this should always return a Hash with String keys
and whose values are basic objects or data structures of the same.
returns:
- description: |-
a serializable hash representation of the
Expand Down
7 changes: 7 additions & 0 deletions docs/_modules/cuprum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ files:
- lib/cuprum/parameter_validation.rb
parent_path: ''
short_description: Toolkit for implementing business logic as function objects.
class_attributes:
- name: initializer
read: true
write: false
path: cuprum/c-initializer
slug: initializer
inherited: false
class_methods:
- name: version
path: cuprum/c-version
Expand Down
28 changes: 28 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ This is the documentation for the [current development build](https://github.com
- For the most recent release, see [Version 1.3]({{site.baseurl}}/versions/1.3).
- For previous releases, see the [Versions]({{site.baseurl}}/versions) page.

## Getting Started

Add the gem to your `Gemfile` or `gemspec`:

```ruby
gem 'cuprum'
```

Require `Cuprum` in your code:

```ruby
require 'cuprum'
```

To ensure that error message definitions are loaded, call the `Cuprum` initializer:

- In the [initializer](./initializer) for your project:

```ruby
module Space
@initializer = SleepingKingStudios::Tools::Toolbox::Initializer.new do
Cuprum.initializer.call
end
end
```

- Or, in the entry points of your application (such as a `bin` script or `spec_helper.rb`).

## Reference

Cuprum defines the following core components:
Expand Down
10 changes: 10 additions & 0 deletions lib/cuprum.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'sleeping_king_studios/tools/toolbox/initializer'

# Toolkit for implementing business logic as function objects.
module Cuprum
autoload :Command, 'cuprum/command'
Expand All @@ -16,7 +18,15 @@ module Cuprum
autoload :ResultList, 'cuprum/result_list'
autoload :Steps, 'cuprum/steps'

@initializer = SleepingKingStudios::Tools::Toolbox::Initializer.new do
SleepingKingStudios::Tools.initializer.call
end

class << self
# @return [SleepingKingStudios::Tools::Toolbox::Initializer] the initializer
# for the module.
attr_reader :initializer

# @return [String] the current version of the gem.
def version
VERSION
Expand Down
8 changes: 4 additions & 4 deletions lib/cuprum/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module Cuprum
class Error
# Short string used to identify the type of error.
#
# Primarily used for serialization. This value can be overriden by passing
# Primarily used for serialization. This value can be overridden by passing
# in the :type parameter to the constructor.
#
# Subclasses of Cuprum::Error should define their own default TYPE constant.
Expand Down Expand Up @@ -86,9 +86,9 @@ def ==(other)
# Generates a serializable representation of the error object.
#
# By default, contains the #type and #message properties and an empty :data
# Hash. This can be overriden in subclasses by overriding the private method
# #as_json_data; this should always return a Hash with String keys and whose
# values are basic objects or data structures of the same.
# Hash. This can be overridden in subclasses by overriding the private
# method #as_json_data; this should always return a Hash with String keys
# and whose values are basic objects or data structures of the same.
#
# @return [Hash<String, Object>] a serializable hash representation of the
# error.
Expand Down
8 changes: 7 additions & 1 deletion spec/cuprum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
end
end

describe '::version' do
describe '.initializer' do
include_examples 'should define class reader',
:initializer,
-> { be_a(SleepingKingStudios::Tools::Toolbox::Initializer) }
end

describe '.version' do
it 'should define the reader' do
expect(described_class)
.to have_reader(:version)
Expand Down
8 changes: 5 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# frozen_string_literal: true

require 'rspec/sleeping_king_studios/all'
require 'byebug'

unless ENV['COVERAGE'] == 'false'
require 'simplecov'

SimpleCov.start
end

require 'rspec/sleeping_king_studios/all'
require 'byebug'
require 'cuprum'

# Isolated namespace for defining spec-only or transient objects.
module Spec; end

SleepingKingStudios::Tools.initializer.call
Cuprum.initializer.call

require 'support/matrix'

Expand Down