opt_struct 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d997efd436a127ccf51efc19590c55f4671c087e61ed085174a273a723d9fc66
4
- data.tar.gz: 87f2650397718c6dad69871202ea303de8626c94d98cab01b1e14ce6e78de82e
3
+ metadata.gz: 85c2fa0b44b80b18c83e3192538d13a93acbf9b4b33ca12ffd833daec925680d
4
+ data.tar.gz: 499734e72e8227e5998dfec858242e3229d332a4d885a3aeda0607418d930971
5
5
  SHA512:
6
- metadata.gz: 8ba6acba66bd8d059d3cc210b5102908929458b6665972e7ba3c049fed4eb6ab1031edf987b0e1d30ba61130d72cf0cdd075587319016924445e075cae4e4a83
7
- data.tar.gz: 9dd91af6395c02a480a9ffe413c1912dba17f30fc7f7e3f175f0b681d485aee8f9cbf91ac136158f6bf82942bd137e3e68082bd9d2d7ac8ba1c2d44e541f7d29
6
+ metadata.gz: 26dd17e556704a4289070db192c387b33985e530d3bb03fee4fd16cbfbe45dbe0fe5051c462ee40a79e9c5c2140f07b4868677fa31b93e2c67025fd470a534f0
7
+ data.tar.gz: 8c582de7a5ac0bfbcc7d9b1d237cc74952803efe7864ecab39e0cd0f5cc4796bac7f23e0e742fe3c1e7c90ae216f3797e315385007986647ea85c7078f71e388
data/README.md CHANGED
@@ -1,7 +1,4 @@
1
- # The Opt Struct [![Build Status][travis-image]][travis-link]
2
-
3
- [travis-image]: https://travis-ci.org/carlzulauf/opt_struct.svg?branch=master
4
- [travis-link]: http://travis-ci.org/carlzulauf/opt_struct
1
+ # The Opt Struct
5
2
 
6
3
  A struct around a hash. Great for encapsulating actions with complex configuration, like interactor/action classes.
7
4
 
@@ -17,7 +14,7 @@ gem "opt_struct"
17
14
  class User < OptStruct.new
18
15
  required :email, :name
19
16
  option :role, default: "member"
20
-
17
+
21
18
  def formatted_email
22
19
  %{"#{name}" <#{email}>}
23
20
  end
@@ -156,7 +153,7 @@ Passing a Hash to `.new` or `.build` is equivalent to passing the same hash to `
156
153
  User = OptStruct.new(email: nil, role: "member")
157
154
  ```
158
155
 
159
- Default blocks can also be used and are late evaluated on the each struct instance.
156
+ Default blocks can also be used and are late evaluated within the struct instance.
160
157
 
161
158
  ```ruby
162
159
  class User < OptStruct.new
@@ -175,9 +172,9 @@ end
175
172
  class User < OptStruct.new
176
173
  option :email, nil
177
174
  option :role, -> { default_role }
178
-
175
+
179
176
  private
180
-
177
+
181
178
  def default_role
182
179
  "member"
183
180
  end
@@ -189,7 +186,7 @@ Default symbols are treated as method calls if the struct `#respond_to?` the met
189
186
  ```ruby
190
187
  class User < OptStruct.new
191
188
  options :email, :role => :default_role
192
-
189
+
193
190
  def default_role
194
191
  "member"
195
192
  end
@@ -268,7 +265,7 @@ end
268
265
 
269
266
  Expected arguments are similar to required arguments, except they are in `.expected_arguments` collection, which is checked when an OptStruct is initialized.
270
267
 
271
- Expected arguments can also be supplied using keywords. An `ArgumentError` is only raised if the expected argument is not in the list of arguments passed to `OptStruct#new` **and** the argument is not present in the `#options` Hash.
268
+ Expected arguments can also be supplied using keywords. An `ArgumentError` is only raised if the expected argument is not in the list of arguments passed to `OptStruct#new` **and** the argument is not present in the optional Hash passed to `OptStruct#new`.
272
269
 
273
270
  The following examples will initialize any of the `User` class examples above without error.
274
271
 
@@ -294,7 +291,7 @@ Feel free to write your own accessor methods for things like dependent options o
294
291
  class Person < OptStruct.new
295
292
  option :given_name
296
293
  option :family_name
297
-
294
+
298
295
  def name
299
296
  options.fetch(:name) { "#{given_name} #{family_name}" }
300
297
  end
@@ -310,7 +307,7 @@ OptStruct classes are initialized in an `initialize` method (in `OptStruct::Inst
310
307
  ```ruby
311
308
  class UserReportBuilder < OptStruct.new(:user)
312
309
  attr_reader :report
313
-
310
+
314
311
  def initialize(*)
315
312
  super
316
313
  @report = []
@@ -318,7 +315,7 @@ class UserReportBuilder < OptStruct.new(:user)
318
315
  end
319
316
  ```
320
317
 
321
- `OptStruct` also provides initialization callbacks to make hooking into and customizing the initialization of OptStruct classes easier and require less code.
318
+ `OptStruct` also provides initialization callbacks to make hooking into and customizing the initialization of OptStruct classes easier, less brittle, and require less code.
322
319
 
323
320
  ```ruby
324
321
  class UserReportBuilder < OptStruct.new(:user)
@@ -330,7 +327,7 @@ end
330
327
  ```ruby
331
328
  class UserReportBuilder < OptStruct.new(:user)
332
329
  attr_reader :report
333
-
330
+
334
331
  around_init do |instance|
335
332
  instance.call
336
333
  @report = []
@@ -17,6 +17,10 @@ module OptStruct
17
17
  self.class.defaults
18
18
  end
19
19
 
20
+ def ==(other)
21
+ options == other.options
22
+ end
23
+
20
24
  private
21
25
 
22
26
  def check_required_keys
@@ -34,7 +38,7 @@ module OptStruct
34
38
  when Proc
35
39
  instance_exec(&default_value)
36
40
  when Symbol
37
- respond_to?(default_value) ? send(default_value) : default_value
41
+ respond_to?(default_value, true) ? send(default_value) : default_value
38
42
  else
39
43
  default_value
40
44
  end
@@ -1,3 +1,3 @@
1
1
  module OptStruct
2
- VERSION = "1.5.2"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opt_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Zulauf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-31 00:00:00.000000000 Z
11
+ date: 2025-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Struct with support for keyword params and mixin support
14
14
  email:
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.2.33
46
+ rubygems_version: 3.5.22
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: The Option Struct