arstotzka 1.6.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +34 -12
- data/.claude/agents/architect.md +48 -0
- data/.claude/agents/infra.md +34 -0
- data/.claude/agents/ruby.md +43 -0
- data/.claude/configuration/arcanum-repo-config.json +3 -0
- data/.claude/scripts/check_infra.sh +6 -0
- data/.claude/scripts/check_ruby.sh +7 -0
- data/.claude/settings.json +10 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -0
- data/.github/pull_request_template.md +17 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +19 -6
- data/AGENTS.md +69 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +6 -9
- data/Gemfile +20 -3
- data/README.md +8 -4
- data/Rakefile +2 -0
- data/arstotzka.gemspec +4 -24
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +64 -0
- data/docs/agents/contributing.md +202 -0
- data/docs/agents/flow.md +28 -0
- data/docs/agents/folder-structure.md +29 -0
- data/docs/agents/issue-enhancement.md +11 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/arstotzka/class_methods.rb +1 -1
- data/lib/arstotzka/crawler.rb +1 -0
- data/lib/arstotzka/exception.rb +1 -0
- data/lib/arstotzka/fetcher/cache.rb +1 -0
- data/lib/arstotzka/key_reader.rb +2 -1
- data/lib/arstotzka/method_builder.rb +1 -0
- data/lib/arstotzka/options.rb +1 -1
- data/lib/arstotzka/reader.rb +1 -0
- data/lib/arstotzka/type_cast.rb +2 -2
- data/lib/arstotzka/version.rb +1 -1
- data/lib/arstotzka/wrapper.rb +17 -1
- data/scripts/bump_version.sh +62 -0
- data/spec/integration/yard/arstotzka/class_methods_spec.rb +1 -0
- data/spec/integration/yard/arstotzka/config_spec.rb +1 -1
- data/spec/integration/yard/arstotzka/fetcher/cache_spec.rb +1 -1
- data/spec/integration/yard/arstotzka/options_spec.rb +2 -4
- data/spec/integration/yard/arstotzka/type_cast_spec.rb +1 -1
- data/spec/integration/yard/arstotzka/wrapper_spec.rb +1 -1
- data/spec/lib/arstotzka/fetcher_spec.rb +1 -1
- data/spec/lib/arstotzka/options_spec.rb +1 -2
- data/spec/lib/arstotzka/type_cast_spec.rb +4 -4
- data/spec/lib/arstotzka/wrapper_spec.rb +4 -3
- data/spec/spec_helper.rb +13 -4
- data/spec/support/models/arstotzka/dummy.rb +1 -0
- data/spec/support/models/arstotzka/wrapper/dummy.rb +1 -0
- data/spec/support/models/car_collector.rb +1 -1
- data/spec/support/models/collector.rb +1 -1
- data/spec/support/models/game.rb +1 -0
- data/spec/support/models/house.rb +1 -0
- data/spec/support/models/my_parser.rb +1 -1
- data/spec/support/models.rb +2 -2
- metadata +32 -329
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Commit Guidelines
|
|
4
|
+
|
|
5
|
+
- **Atomic and Unitary:** Each commit must represent a single logical change.
|
|
6
|
+
*Example:*
|
|
7
|
+
- Good: `Add before option to Wrapper`
|
|
8
|
+
- Bad: `Add before option and refactor Crawler logic`
|
|
9
|
+
- **No Unrelated Changes:** Do not mix unrelated changes in the same commit.
|
|
10
|
+
- **Separate Refactoring:** Whenever possible, separate refactoring commits from new feature or bugfix commits.
|
|
11
|
+
|
|
12
|
+
## Pull Requests
|
|
13
|
+
|
|
14
|
+
- **Descriptive Summary:** Every PR must include a clear and descriptive summary of its purpose and changes.
|
|
15
|
+
- **PR Description Files:** If a description cannot be provided directly in the PR, generate a file with the PR description (e.g., `docs/agents/issues/<pr_number>_description.md`), but do not commit this file.
|
|
16
|
+
|
|
17
|
+
## Definition of Done for PRs
|
|
18
|
+
|
|
19
|
+
A PR is considered complete when:
|
|
20
|
+
|
|
21
|
+
- The stated objective has been achieved.
|
|
22
|
+
- All tests are passing.
|
|
23
|
+
- Linting (`rubocop`) passes without errors.
|
|
24
|
+
- Code coverage is as high as reasonably possible.
|
|
25
|
+
- New/changed public code is documented with YARD and Yardstick coverage does not drop.
|
|
26
|
+
- `@example` blocks added to YARD docs or `README.md` are covered by specs in
|
|
27
|
+
`spec/integration/yard` or `spec/integration/readme`.
|
|
28
|
+
- When the version is bumped, `README.md` links the new version's YARD docs.
|
|
29
|
+
- Code is not overly complex:
|
|
30
|
+
- Classes and methods should have clear, focused responsibilities.
|
|
31
|
+
- If a class or method is taking on too many responsibilities, refactor to simplify.
|
|
32
|
+
- Methods should be small and do exactly one thing. If a method is growing, extract parts into private helper methods or separate classes.
|
|
33
|
+
- *Example:*
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
# Good: each method does one thing
|
|
37
|
+
class Fetcher
|
|
38
|
+
def fetch
|
|
39
|
+
post_processor.process(crawler.value(hash))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def crawler
|
|
45
|
+
@crawler ||= Crawler.new(options)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Bad: one method does too much
|
|
50
|
+
class Fetcher
|
|
51
|
+
def fetch
|
|
52
|
+
hash = options.instance.send(options.json)
|
|
53
|
+
value = options.keys.inject(hash) { |h, key| h[key.to_s] || h[key.to_sym] }
|
|
54
|
+
value = value.flatten if options.flatten
|
|
55
|
+
options.instance.send(options.after, value)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- This requirement applies primarily to source code. For specs, refactor only if there is excessive duplication.
|
|
61
|
+
|
|
62
|
+
### CI Checks
|
|
63
|
+
|
|
64
|
+
Before a PR is considered complete, all CI checks relevant to the modified parts of the project must pass locally.
|
|
65
|
+
|
|
66
|
+
The project has a single CircleCI `test` job, run for every change:
|
|
67
|
+
|
|
68
|
+
| Modified folder | CircleCI job | Local commands |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| any (`lib/`, `spec/`, `config/`, `README.md`, ...) | `test` | `bundle exec rspec`<br>`rubocop`<br>`bundle exec rake verify_measurements` (Yardstick)<br>`scripts/check_readme.sh` (README links current version docs)<br>`bundle exec rubycritic --format console --branch origin/master -t 0 --maximum-decrease 1 <changed lib files>`<br>every `lib/` file has a spec under `spec/lib/` (`check_specs`, see `config/check_specs.yml`) |
|
|
71
|
+
|
|
72
|
+
The same can be run in Docker with `docker-compose run test_all` (RSpec + YARD + Yardstick)
|
|
73
|
+
plus `docker-compose run arstotzka rubocop`.
|
|
74
|
+
|
|
75
|
+
The `build-and-release` job only runs on version tags on `master` and needs no local check.
|
|
76
|
+
|
|
77
|
+
This same process must be followed when **planning how to resolve an issue**: include a final step in the plan that lists the CI commands to run before opening a PR.
|
|
78
|
+
|
|
79
|
+
## Code Organization
|
|
80
|
+
|
|
81
|
+
### File Responsibility: Class Declarers vs Scripts
|
|
82
|
+
|
|
83
|
+
Every source file under `lib/` must act as a **class declarer** — it should define one class or module. Files must not act as **scripts** (i.e., they must not execute logic at load time or perform side effects directly).
|
|
84
|
+
|
|
85
|
+
The only entrypoint is `lib/arstotzka.rb`, which requires dependencies, defines the
|
|
86
|
+
`Arstotzka` concern, autoloads the other classes and calls `configurable_by`.
|
|
87
|
+
|
|
88
|
+
*Example:*
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
# Good: class declarer
|
|
92
|
+
module Arstotzka
|
|
93
|
+
class KeyChanger
|
|
94
|
+
def initialize(base_key, options_hash = {})
|
|
95
|
+
...
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Bad: script — executes logic at load time
|
|
101
|
+
changer = Arstotzka::KeyChanger.new('the_key', case: :lower_camel)
|
|
102
|
+
puts changer.key
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Spec files are exempt from this rule and may execute setup code freely.
|
|
106
|
+
|
|
107
|
+
### File Naming: snake_case Matching the Class
|
|
108
|
+
|
|
109
|
+
Files use **snake_case** naming matching the class or module they define, and the
|
|
110
|
+
directory structure mirrors the namespace:
|
|
111
|
+
|
|
112
|
+
- `Arstotzka::KeyChanger` → `lib/arstotzka/key_changer.rb`
|
|
113
|
+
- `Arstotzka::Fetcher::Cache` → `lib/arstotzka/fetcher/cache.rb`
|
|
114
|
+
|
|
115
|
+
Specs mirror the source path with a `_spec.rb` suffix:
|
|
116
|
+
|
|
117
|
+
- `lib/arstotzka/key_changer.rb` → `spec/lib/arstotzka/key_changer_spec.rb`
|
|
118
|
+
|
|
119
|
+
New classes must also be registered with `autoload` in `lib/arstotzka.rb`.
|
|
120
|
+
|
|
121
|
+
### Method Order: Public Before Private
|
|
122
|
+
|
|
123
|
+
Within a class, **public methods must be declared before `protected` and `private` methods**. Private methods serve as implementation helpers and appear at the end of the class body.
|
|
124
|
+
|
|
125
|
+
*Example:*
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
# Good: public methods first, private methods last
|
|
129
|
+
class Wrapper
|
|
130
|
+
def wrap(value)
|
|
131
|
+
return wrap_array(value) if value.is_a?(Array)
|
|
132
|
+
|
|
133
|
+
wrap_element(value)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
private
|
|
137
|
+
|
|
138
|
+
def wrap_array(array) ... end
|
|
139
|
+
def wrap_element(value) ... end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Bad: private helpers mixed in before public methods
|
|
143
|
+
class Wrapper
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def wrap_array(array) ... end
|
|
147
|
+
|
|
148
|
+
public
|
|
149
|
+
|
|
150
|
+
def wrap(value) ... end
|
|
151
|
+
end
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Dependency Injection
|
|
155
|
+
|
|
156
|
+
Classes must receive their dependencies (data, options, collaborators) as constructor arguments. A class must never reach out to load files, read environment variables, or fetch configuration on its own.
|
|
157
|
+
|
|
158
|
+
In Arstotzka, global configuration is resolved once — by `FetcherBuilder#build` via
|
|
159
|
+
`Arstotzka.config.options(...)` — and the resulting `Options` object (including the
|
|
160
|
+
`instance`) is passed down to every collaborator (`Fetcher`, `Crawler`, `Wrapper`, ...).
|
|
161
|
+
|
|
162
|
+
This makes every class independently testable: specs simply instantiate the class with the options they need.
|
|
163
|
+
|
|
164
|
+
*Example:*
|
|
165
|
+
|
|
166
|
+
```ruby
|
|
167
|
+
# Good: class receives options as an argument — easy to test
|
|
168
|
+
class Wrapper
|
|
169
|
+
def initialize(options = {})
|
|
170
|
+
@options = options
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
Arstotzka::Wrapper.new(type: :integer).wrap('10') # => 10
|
|
175
|
+
|
|
176
|
+
# Bad: class reads global configuration on its own
|
|
177
|
+
class Wrapper
|
|
178
|
+
def wrap(value)
|
|
179
|
+
cast(value, Arstotzka.config.type) # ❌
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
This principle applies to all classes — including helpers. If a class needs data, it gets it through its constructor.
|
|
185
|
+
|
|
186
|
+
## Refactoring Guidelines
|
|
187
|
+
|
|
188
|
+
When refactoring, aim to:
|
|
189
|
+
|
|
190
|
+
- **Reduce Code Duplication:**
|
|
191
|
+
*Example:* Move repeated setup in specs to `let` blocks, shared examples
|
|
192
|
+
(`spec/support/shared_examples`) or support models (`spec/support/models`).
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
# Good
|
|
196
|
+
let(:options) { { path: 'person', case: :snake } }
|
|
197
|
+
let(:fetcher) { described_class.new(options.merge(instance: instance)) }
|
|
198
|
+
|
|
199
|
+
# Bad
|
|
200
|
+
fetcher = described_class.new(path: 'person', case: :snake, instance: instance)
|
|
201
|
+
# ...repeated in many examples
|
|
202
|
+
```
|
data/docs/agents/flow.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Flow
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
### Declaration (class load time)
|
|
6
|
+
|
|
7
|
+
1. `include Arstotzka` extends the class with `Arstotzka::ClassMethods`.
|
|
8
|
+
2. `expose :attr, **options` creates an `Arstotzka::MethodBuilder` with the attribute names
|
|
9
|
+
and options.
|
|
10
|
+
3. For each attribute, `MethodBuilder` registers a `FetcherBuilder` in the class
|
|
11
|
+
(`add_fetcher`) and defines the instance method `attr`.
|
|
12
|
+
|
|
13
|
+
### Fetching (method call time)
|
|
14
|
+
|
|
15
|
+
1. `instance.attr` calls `self.class.fetcher_for(:attr, self)`, which finds the
|
|
16
|
+
`FetcherBuilder` (looking up superclasses) and builds a `Fetcher` with
|
|
17
|
+
`Arstotzka.config.options(options.merge(instance: self))`.
|
|
18
|
+
2. `Fetcher#fetch` goes through `Fetcher::Cache`: if `cached` is set and a value is
|
|
19
|
+
already stored, it is returned.
|
|
20
|
+
3. Otherwise `HashReader` gets the hash from the instance (the `json` option).
|
|
21
|
+
4. `Crawler#value` walks the keys (`path` + attribute name, or `full_path`), using `Reader`
|
|
22
|
+
→ `KeyReader` → `KeyChanger` to read each key in the configured case. Arrays are
|
|
23
|
+
crawled element by element; missing keys yield `default`, and `compact` drops `nil`s.
|
|
24
|
+
5. Each final value passes through `Wrapper#wrap`: `before`, type cast (`TypeCast`),
|
|
25
|
+
wrapping in `klass`, and `after_each`.
|
|
26
|
+
6. `PostProcessor#process` applies `flatten` and calls the instance's `after` method on
|
|
27
|
+
the whole result.
|
|
28
|
+
7. The result is cached (if requested) and returned.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Folder Structure
|
|
2
|
+
|
|
3
|
+
## Project Root
|
|
4
|
+
|
|
5
|
+
| Directory / File | Description |
|
|
6
|
+
|-----------------|-------------|
|
|
7
|
+
| `lib/` | Gem source code: `lib/arstotzka.rb` (the concern entrypoint) and `lib/arstotzka/` (internal classes). See [architecture.md](architecture.md). |
|
|
8
|
+
| `spec/` | RSpec test suite (unit, integration, fixtures and support models). |
|
|
9
|
+
| `config/` | Configuration for quality tooling: Yardstick (`yardstick.rb`, `yardstick.yml`), RubyCritic (`rubycritc.rb`) and `check_specs.yml` (lib files exempt from requiring a spec). |
|
|
10
|
+
| `scripts/` | CI helper scripts: `check_readme.sh` (README links the current version's YARD docs) and `rubycritic.sh` (RubyCritic comparison against `master`). |
|
|
11
|
+
| `docs/agents/` | Agent-facing documentation, issue files and implementation plans. |
|
|
12
|
+
| `.circleci/` | CircleCI pipeline: `test` job (RSpec, RuboCop, coverage, Yardstick, README check, RubyCritic, check_specs) and `build-and-release` job (gem push on version tags). |
|
|
13
|
+
| `.github/` | PR template, commit message template and Copilot instructions. |
|
|
14
|
+
| `arstotzka.gemspec` | Gem specification and dependencies. |
|
|
15
|
+
| `Dockerfile`, `docker-compose.yml` | Containerised development environment (`arstotzka` runs RSpec, `test_all` runs RSpec + YARD + Yardstick). |
|
|
16
|
+
| `Rakefile` | Rake tasks: RSpec, gem tasks, Yardstick measurement/verification. |
|
|
17
|
+
| `.rubocop.yml`, `.rubocop_todo.yml` | RuboCop configuration. |
|
|
18
|
+
| `.yardopts` | YARD documentation options. |
|
|
19
|
+
| `README.md` | User-facing documentation with usage examples (exercised by `spec/integration/readme`). |
|
|
20
|
+
|
|
21
|
+
## spec/
|
|
22
|
+
|
|
23
|
+
| Subdirectory | Description |
|
|
24
|
+
|--------------|-------------|
|
|
25
|
+
| `lib/` | Unit specs mirroring `lib/` one-to-one (`lib/arstotzka/foo.rb` → `spec/lib/arstotzka/foo_spec.rb`). |
|
|
26
|
+
| `integration/readme/` | Specs asserting the examples from `README.md` work. |
|
|
27
|
+
| `integration/yard/` | Specs asserting the `@example` blocks from the YARD docs work. |
|
|
28
|
+
| `fixtures/` | JSON fixtures loaded by specs. |
|
|
29
|
+
| `support/` | Spec helpers, shared examples and `models/` — sample classes including `Arstotzka` used by specs and doc examples. |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Issue Enhancement
|
|
2
|
+
|
|
3
|
+
A checklist of concerns to consider when fleshing out a vague issue idea (tagged `Idea`/`Writting`) before it reaches the `Created` stage. Not exhaustive — adjust or extend the list for this project's needs.
|
|
4
|
+
|
|
5
|
+
- **Scope boundaries** — what's explicitly in scope and what's explicitly out.
|
|
6
|
+
- **Alternative solutions** — other ways to solve the same problem, and why this one was chosen.
|
|
7
|
+
- **Edge cases** — inputs, states, or timing the happy path doesn't cover.
|
|
8
|
+
- **Backward compatibility** — whether this breaks existing behavior, data, or integrations.
|
|
9
|
+
- **Testing strategy** — how the change will be verified.
|
|
10
|
+
- **Performance & security considerations** — anything relevant to load, latency, or attack surface.
|
|
11
|
+
- **Public API & docs impact** — new or changed `expose` options / public classes, required YARD docs and README examples (with their integration specs), and whether a version bump is needed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -43,7 +43,7 @@ module Arstotzka
|
|
|
43
43
|
# @return [TrueClass,FalseClass]
|
|
44
44
|
def fetcher_for?(attribute)
|
|
45
45
|
return true if fetcher_builders.key?(attribute)
|
|
46
|
-
return unless superclass.include?(Arstotzka)
|
|
46
|
+
return false unless superclass.include?(Arstotzka)
|
|
47
47
|
|
|
48
48
|
superclass.fetcher_for?(attribute)
|
|
49
49
|
end
|
data/lib/arstotzka/crawler.rb
CHANGED
data/lib/arstotzka/exception.rb
CHANGED
data/lib/arstotzka/key_reader.rb
CHANGED
|
@@ -48,6 +48,7 @@ module Arstotzka
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
50
|
attr_reader :hash, :base_key, :options
|
|
51
|
+
|
|
51
52
|
delegate :key, to: :key_changer
|
|
52
53
|
|
|
53
54
|
# @private
|
|
@@ -61,7 +62,7 @@ module Arstotzka
|
|
|
61
62
|
#
|
|
62
63
|
# @see #check_key!
|
|
63
64
|
def key?
|
|
64
|
-
return unless hash
|
|
65
|
+
return false unless hash
|
|
65
66
|
|
|
66
67
|
hash.key?(key) || hash.key?(key.to_sym)
|
|
67
68
|
end
|
data/lib/arstotzka/options.rb
CHANGED
data/lib/arstotzka/reader.rb
CHANGED
data/lib/arstotzka/type_cast.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Arstotzka
|
|
|
37
37
|
# module Arstotzka
|
|
38
38
|
# module TypeCast
|
|
39
39
|
# def to_car(hash)
|
|
40
|
-
# Car.new(hash.symbolize_keys)
|
|
40
|
+
# Car.new(**hash.symbolize_keys)
|
|
41
41
|
# end
|
|
42
42
|
# end
|
|
43
43
|
# end
|
|
@@ -120,7 +120,7 @@ module Arstotzka
|
|
|
120
120
|
#
|
|
121
121
|
# model.TypeCaster.new(hash)
|
|
122
122
|
#
|
|
123
|
-
# model.payload # returns '{"key"=>"value"}'
|
|
123
|
+
# model.payload # returns '{"key" => "value"}'
|
|
124
124
|
def to_string(value)
|
|
125
125
|
value.to_s
|
|
126
126
|
end
|
data/lib/arstotzka/version.rb
CHANGED
data/lib/arstotzka/wrapper.rb
CHANGED
|
@@ -56,7 +56,7 @@ module Arstotzka
|
|
|
56
56
|
# wrapper = Arstotzka::Wrapper.new(type: :string, klass: Request)
|
|
57
57
|
# request = wrapper.wrap(value)
|
|
58
58
|
#
|
|
59
|
-
# request.payload # returns '{"key"=>"value"}'
|
|
59
|
+
# request.payload # returns '{"key" => "value"}'
|
|
60
60
|
def wrap(value)
|
|
61
61
|
return wrap_array(value) if value.is_a?(Array)
|
|
62
62
|
|
|
@@ -67,6 +67,7 @@ module Arstotzka
|
|
|
67
67
|
|
|
68
68
|
# @private
|
|
69
69
|
attr_reader :options
|
|
70
|
+
|
|
70
71
|
delegate :klass, :type, :after_each, to: :options
|
|
71
72
|
|
|
72
73
|
# @private
|
|
@@ -133,13 +134,28 @@ module Arstotzka
|
|
|
133
134
|
#
|
|
134
135
|
# Wrap resulting value in class
|
|
135
136
|
#
|
|
137
|
+
# When the value is a +Hash+ and the class initializer
|
|
138
|
+
# accepts keyword arguments, the hash is passed as keywords
|
|
139
|
+
#
|
|
136
140
|
# @return [Object] instance of +options.klass+
|
|
137
141
|
def wrap_in_class(value)
|
|
138
142
|
return value unless klass
|
|
143
|
+
return klass.new(**value) if value.is_a?(Hash) && keyword_initializer?
|
|
139
144
|
|
|
140
145
|
klass.new(value)
|
|
141
146
|
end
|
|
142
147
|
|
|
148
|
+
# @private
|
|
149
|
+
#
|
|
150
|
+
# Checks if +options.klass+ initializer accepts keyword arguments
|
|
151
|
+
#
|
|
152
|
+
# @return [TrueClass,FalseClass]
|
|
153
|
+
def keyword_initializer?
|
|
154
|
+
klass.instance_method(:initialize).parameters.any? do |type, _|
|
|
155
|
+
%i[key keyreq keyrest].include?(type)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
143
159
|
# @private
|
|
144
160
|
#
|
|
145
161
|
# Process and wrap value trhough a method call
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Usage: scripts/bump_version.sh [major|minor|patch|X.Y.Z]
|
|
3
|
+
# Without arguments, bumps the patch version of the current version.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
ROOT="$(git rev-parse --show-toplevel)"
|
|
8
|
+
README="$ROOT/README.md"
|
|
9
|
+
VERSION_FILE="$ROOT/lib/arstotzka/version.rb"
|
|
10
|
+
LOCKFILE="$ROOT/Gemfile.lock"
|
|
11
|
+
GEM="arstotzka"
|
|
12
|
+
|
|
13
|
+
current=$(grep -oE "VERSION = '[0-9]+\.[0-9]+\.[0-9]+'" "$VERSION_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
|
|
14
|
+
IFS='.' read -r cmajor cminor cpatch <<< "$current"
|
|
15
|
+
|
|
16
|
+
arg="${1:-patch}"
|
|
17
|
+
|
|
18
|
+
case "$arg" in
|
|
19
|
+
major) new_version="$((cmajor + 1)).0.0" ;;
|
|
20
|
+
minor) new_version="${cmajor}.$((cminor + 1)).0" ;;
|
|
21
|
+
patch) new_version="${cmajor}.${cminor}.$((cpatch + 1))" ;;
|
|
22
|
+
*) new_version="$arg" ;;
|
|
23
|
+
esac
|
|
24
|
+
|
|
25
|
+
# Validate semver format
|
|
26
|
+
if ! echo "$new_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
|
|
27
|
+
echo "Error: version must be major, minor, patch or X.Y.Z" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Next release: following minor
|
|
32
|
+
IFS='.' read -r major minor _patch <<< "$new_version"
|
|
33
|
+
next_release="${major}.$((minor + 1)).0"
|
|
34
|
+
|
|
35
|
+
echo "Current version: $current"
|
|
36
|
+
echo "New version: $new_version"
|
|
37
|
+
echo "Next release: $next_release"
|
|
38
|
+
|
|
39
|
+
# version.rb
|
|
40
|
+
sed -i '' "s|VERSION = '[0-9.]*'|VERSION = '${new_version}'|" "$VERSION_FILE"
|
|
41
|
+
|
|
42
|
+
# README: YARD docs link
|
|
43
|
+
sed -i '' \
|
|
44
|
+
"s|rubydoc.info/gems/${GEM}/[0-9.]*|rubydoc.info/gems/${GEM}/${new_version}|g" \
|
|
45
|
+
"$README"
|
|
46
|
+
|
|
47
|
+
# README: Current Release line
|
|
48
|
+
sed -i '' \
|
|
49
|
+
"s|\*\*Current Release\*\*: \[[0-9.]*\](https://github.com/darthjee/arstotzka/tree/[0-9.]*)|**Current Release**: [${new_version}](https://github.com/darthjee/arstotzka/tree/${new_version})|" \
|
|
50
|
+
"$README"
|
|
51
|
+
|
|
52
|
+
# README: Next release line
|
|
53
|
+
sed -i '' \
|
|
54
|
+
"s|\*\*Next release\*\*: \[[0-9.]*\](https://github.com/darthjee/arstotzka/compare/[0-9.]*\.\.\.main)|**Next release**: [${next_release}](https://github.com/darthjee/arstotzka/compare/${new_version}...main)|" \
|
|
55
|
+
"$README"
|
|
56
|
+
|
|
57
|
+
# Gemfile.lock
|
|
58
|
+
if [ -f "$LOCKFILE" ]; then
|
|
59
|
+
sed -i '' "s|^\( *${GEM} (\)[0-9.]*)|\1${new_version})|" "$LOCKFILE"
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
echo "Done."
|
|
@@ -49,22 +49,21 @@ describe Arstotzka::Options do
|
|
|
49
49
|
]
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
# rubocop:disable RSpec/LeakyConstantDeclaration
|
|
53
52
|
before do
|
|
53
|
+
# rubocop:disable-next Lint/ConstantDefinitionInBlock
|
|
54
54
|
module Arstotzka::TypeCast
|
|
55
55
|
def to_symbolized_hash(value)
|
|
56
56
|
value.symbolize_keys
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
|
-
# rubocop:enable RSpec/LeakyConstantDeclaration
|
|
61
60
|
|
|
62
61
|
it 'returns inflated drinks' do
|
|
63
62
|
expect(instance.drinks).to eq(expected)
|
|
64
63
|
end
|
|
65
64
|
end
|
|
66
65
|
|
|
67
|
-
# rubocop:disable RSpec/SubjectStub
|
|
66
|
+
# rubocop:disable-next RSpec/SubjectStub
|
|
68
67
|
describe 'Using cached, compact, after and full_path' do
|
|
69
68
|
let(:clazz) { Application }
|
|
70
69
|
|
|
@@ -101,7 +100,6 @@ describe Arstotzka::Options do
|
|
|
101
100
|
expect(instance).to have_received(:warn).exactly(3).times
|
|
102
101
|
end
|
|
103
102
|
end
|
|
104
|
-
# rubocop:enable RSpec/SubjectStub
|
|
105
103
|
|
|
106
104
|
describe 'working with snake case hash' do
|
|
107
105
|
let(:clazz) { JobSeeker }
|
|
@@ -160,7 +160,7 @@ describe Arstotzka::Options do
|
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
# rubocop:disable RSpec/SubjectStub
|
|
163
|
-
# rubocop:disable RSpec/AnyInstance
|
|
163
|
+
# rubocop:disable-next RSpec/AnyInstance
|
|
164
164
|
describe '#klass' do
|
|
165
165
|
before do
|
|
166
166
|
allow_any_instance_of(described_class)
|
|
@@ -191,7 +191,6 @@ describe Arstotzka::Options do
|
|
|
191
191
|
end
|
|
192
192
|
end
|
|
193
193
|
end
|
|
194
|
-
# rubocop:enable RSpec/AnyInstance
|
|
195
194
|
# rubocop:enable RSpec/SubjectStub
|
|
196
195
|
|
|
197
196
|
describe '#merge' do
|
|
@@ -9,7 +9,7 @@ describe Arstotzka::TypeCast do
|
|
|
9
9
|
|
|
10
10
|
describe '.to_integer' do
|
|
11
11
|
context 'when value is nil' do
|
|
12
|
-
let(:value) {}
|
|
12
|
+
let(:value) { nil }
|
|
13
13
|
|
|
14
14
|
it { expect(caster.to_integer(value)).to be_nil }
|
|
15
15
|
end
|
|
@@ -71,7 +71,7 @@ describe Arstotzka::TypeCast do
|
|
|
71
71
|
|
|
72
72
|
describe '.to_string' do
|
|
73
73
|
context 'when value is nil' do
|
|
74
|
-
let(:value) {}
|
|
74
|
+
let(:value) { nil }
|
|
75
75
|
|
|
76
76
|
it { expect(caster.to_string(value)).to eq('') }
|
|
77
77
|
end
|
|
@@ -111,7 +111,7 @@ describe Arstotzka::TypeCast do
|
|
|
111
111
|
|
|
112
112
|
describe '.to_float' do
|
|
113
113
|
context 'when value is nil' do
|
|
114
|
-
let(:value) {}
|
|
114
|
+
let(:value) { nil }
|
|
115
115
|
|
|
116
116
|
it { expect(caster.to_float(value)).to be_nil }
|
|
117
117
|
end
|
|
@@ -172,7 +172,7 @@ describe Arstotzka::TypeCast do
|
|
|
172
172
|
|
|
173
173
|
describe '.to_symbol' do
|
|
174
174
|
context 'when value is nil' do
|
|
175
|
-
let(:value) {}
|
|
175
|
+
let(:value) { nil }
|
|
176
176
|
|
|
177
177
|
it { expect(caster.to_symbol(value)).to be_nil }
|
|
178
178
|
end
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe Arstotzka::Wrapper do
|
|
6
|
+
subject { described_class.new options }
|
|
7
|
+
|
|
6
8
|
let(:options) { {} }
|
|
7
|
-
let(:subject) { described_class.new options }
|
|
8
9
|
let(:hash) { { a: 1 } }
|
|
9
10
|
|
|
10
11
|
describe '#wrap' do
|
|
@@ -65,7 +66,7 @@ describe Arstotzka::Wrapper do
|
|
|
65
66
|
expect(result.name).to eq(hash[:name])
|
|
66
67
|
end
|
|
67
68
|
|
|
68
|
-
it 'updates the hash before
|
|
69
|
+
it 'updates the hash before' do
|
|
69
70
|
expect(result.age).to eq(10)
|
|
70
71
|
end
|
|
71
72
|
|
|
@@ -84,7 +85,7 @@ describe Arstotzka::Wrapper do
|
|
|
84
85
|
expect(result.map(&:name)).to all(eq(hash[:name]))
|
|
85
86
|
end
|
|
86
87
|
|
|
87
|
-
it 'updates the hash before
|
|
88
|
+
it 'updates the hash before' do
|
|
88
89
|
expect(result.map(&:age)).to all(eq(10))
|
|
89
90
|
end
|
|
90
91
|
end
|