strict 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bf58678470f8cc840c19af0f64ce47ea55abe7124779d1b37ebe10707708d41
4
- data.tar.gz: 02fb60b1183ab1d5eb90c8438a2271512db588438e75f1f89958e67325788360
3
+ metadata.gz: 82ad76d91d34f1bd4cc46ea38e4cef3c03c7d7e328f04d3dcc3c555da1eabdb4
4
+ data.tar.gz: 73f3ca6bc1d03caa42c23f61a3615ccb55285a1dcd962e978be3a87064abf8a3
5
5
  SHA512:
6
- metadata.gz: e333d0836e79b87dfe89fbdc88c915506609a815b1bfce94b4432f40cdf87696c94da52294d3410d11faa48de6c2197194f8be1216cc50ccce2fc9871ab543fc
7
- data.tar.gz: 14c429b220b1a1c890f164daf50dbda22b86d85659abd1c4a8980abd90785d6c52efc7840af85a75740f2dd928c45861d1244061eb703f5e1461b4cabbe8c2f9
6
+ metadata.gz: c442d7d203a993681c89694052856d125ab7c35965fb965ed64250a3eb83476069d844488d64798afc7ddc57b1edafbbbe0d6807b92b3c3a228bf9f3891beecd
7
+ data.tar.gz: 545e4e331d8ed3e578e72dbb52347bb34a0512fa899ca1da60f3181a2836d06a188658b224feed112a2e21464723833230b750628a1d837346566730375ce803
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
 
5
5
  AllCops:
6
6
  NewCops: enable
7
- TargetRubyVersion: 3.1.2
7
+ TargetRubyVersion: 3.0.0
8
8
 
9
9
  Style/CaseEquality:
10
10
  Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.0
data/Gemfile.lock CHANGED
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strict (1.1.0)
4
+ strict (1.2.0)
5
5
  zeitwerk (~> 2.6)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.2)
11
- debug (1.6.1)
11
+ debug (1.6.2)
12
12
  irb (>= 1.3.6)
13
13
  reline (>= 0.3.1)
14
14
  gem-release (2.2.2)
15
15
  io-console (0.5.11)
16
- irb (1.4.1)
16
+ irb (1.4.2)
17
17
  reline (>= 0.3.0)
18
18
  json (2.6.2)
19
- minitest (5.16.2)
19
+ minitest (5.16.3)
20
20
  minitest-spec-context (0.0.4)
21
21
  parallel (1.22.1)
22
22
  parser (3.1.2.1)
@@ -63,4 +63,4 @@ DEPENDENCIES
63
63
  strict!
64
64
 
65
65
  BUNDLED WITH
66
- 2.3.22
66
+ 2.3.23
@@ -12,11 +12,11 @@ module Strict
12
12
  @configuration = configuration
13
13
  const_set(Strict::Attributes::Class::CONSTANT, configuration)
14
14
  configuration.attributes.each do |attribute|
15
- module_eval(
16
- "def #{attribute.name} = #{attribute.instance_variable}", # def name = @instance_variable
17
- __FILE__,
18
- __LINE__ - 2
19
- )
15
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
16
+ def #{attribute.name} # def name
17
+ #{attribute.instance_variable} # @instance_variable
18
+ end # end
19
+ RUBY
20
20
 
21
21
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
22
22
  def #{attribute.name}=(value) # def name=(value)
@@ -28,7 +28,7 @@ module Strict
28
28
  raise Strict::AssignmentError.new( # raise Strict::AssignmentError.new(
29
29
  assignable_class: self.class, # assignable_class: self.class,
30
30
  invalid_attribute: attribute, # invalid_attribute: attribute,
31
- value: # value:
31
+ value: value # value: value
32
32
  ) # )
33
33
  end # end
34
34
  end # end
@@ -5,7 +5,7 @@ module Strict
5
5
  attr_reader :invalid_attribute, :value
6
6
 
7
7
  def initialize(assignable_class:, invalid_attribute:, value:)
8
- super(message_from(assignable_class:, invalid_attribute:, value:))
8
+ super(message_from(assignable_class: assignable_class, invalid_attribute: invalid_attribute, value: value))
9
9
 
10
10
  @invalid_attribute = invalid_attribute
11
11
  @value = value
@@ -10,7 +10,12 @@ module Strict
10
10
  raise ArgumentError, "Only one of 'default', 'default_value', or 'default_generator' can be provided"
11
11
  end
12
12
 
13
- new(name: name.to_sym, validator:, default_generator: make_default_generator(**defaults), coercer: coerce)
13
+ new(
14
+ name: name.to_sym,
15
+ validator: validator,
16
+ default_generator: make_default_generator(**defaults),
17
+ coercer: coerce
18
+ )
14
19
  end
15
20
 
16
21
  private
@@ -12,7 +12,7 @@ module Strict
12
12
  attr_reader :attribute_name
13
13
 
14
14
  def initialize(attribute_name:)
15
- super(message_from(attribute_name:))
15
+ super(message_from(attribute_name: attribute_name))
16
16
 
17
17
  @attribute_name = attribute_name
18
18
  end
@@ -4,9 +4,9 @@ module Strict
4
4
  module Attributes
5
5
  class Dsl < BasicObject
6
6
  class << self
7
- def run(&)
7
+ def run(&block)
8
8
  dsl = new
9
- dsl.instance_eval(&)
9
+ dsl.instance_eval(&block)
10
10
  ::Strict::Attributes::Configuration.new(attributes: dsl.__strict_dsl_internal_attributes.values)
11
11
  end
12
12
  end
@@ -33,9 +33,9 @@ module Strict
33
33
 
34
34
  raise InitializationError.new(
35
35
  initializable_class: self.class,
36
- remaining_attributes:,
37
- invalid_attributes:,
38
- missing_attributes:
36
+ remaining_attributes: remaining_attributes,
37
+ invalid_attributes: invalid_attributes,
38
+ missing_attributes: missing_attributes
39
39
  )
40
40
  end
41
41
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
@@ -4,8 +4,15 @@ module Strict
4
4
  class ImplementationDoesNotConformError < Error
5
5
  attr_reader :interface, :receiver, :missing_methods, :invalid_method_definitions
6
6
 
7
- def initialize(interface:, receiver:, missing_methods:, invalid_method_definitions:)
8
- super(message_from(interface:, receiver:, missing_methods:, invalid_method_definitions:))
7
+ def initialize(interface:, receiver:, missing_methods:, invalid_method_definitions:) # rubocop:disable Metrics/MethodLength
8
+ super(
9
+ message_from(
10
+ interface: interface,
11
+ receiver: receiver,
12
+ missing_methods: missing_methods,
13
+ invalid_method_definitions: invalid_method_definitions
14
+ )
15
+ )
9
16
 
10
17
  @interface = interface
11
18
  @receiver = receiver
@@ -4,8 +4,15 @@ module Strict
4
4
  class InitializationError < Error
5
5
  attr_reader :remaining_attributes, :invalid_attributes, :missing_attributes
6
6
 
7
- def initialize(initializable_class:, remaining_attributes:, invalid_attributes:, missing_attributes:)
8
- super(message_from(initializable_class:, remaining_attributes:, invalid_attributes:, missing_attributes:))
7
+ def initialize(initializable_class:, remaining_attributes:, invalid_attributes:, missing_attributes:) # rubocop:disable Metrics/MethodLength
8
+ super(
9
+ message_from(
10
+ initializable_class: initializable_class,
11
+ remaining_attributes: remaining_attributes,
12
+ invalid_attributes: invalid_attributes,
13
+ missing_attributes: missing_attributes
14
+ )
15
+ )
9
16
 
10
17
  @remaining_attributes = remaining_attributes
11
18
  @invalid_attributes = invalid_attributes
@@ -7,13 +7,14 @@ module Strict
7
7
  mod.include(Interfaces::Instance)
8
8
  end
9
9
 
10
- def expose(method_name, &)
11
- sig = sig(&)
10
+ def expose(method_name, &block)
11
+ sig = sig(&block)
12
12
  parameter_list = sig.parameters.map { |parameter| "#{parameter.name}:" }.join(", ")
13
+ argument_list = sig.parameters.map { |parameter| "#{parameter.name}: #{parameter.name}" }.join(", ")
13
14
 
14
15
  module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
15
16
  def #{method_name}(#{parameter_list}, &block) # def method_name(one:, two:, three:, &block)
16
- implementation.#{method_name}(#{parameter_list}, &block) # implementation.method_name(one:, two:, three:, &block)
17
+ implementation.#{method_name}(#{argument_list}, &block) # implementation.method_name(one: one, two: two, three: three, &block)
17
18
  end # end
18
19
  RUBY
19
20
  end
@@ -41,8 +41,8 @@ module Strict
41
41
  raise Strict::ImplementationDoesNotConformError.new(
42
42
  interface: self.class,
43
43
  receiver: implementation,
44
- missing_methods:,
45
- invalid_method_definitions:
44
+ missing_methods: missing_methods,
45
+ invalid_method_definitions: invalid_method_definitions
46
46
  )
47
47
  end
48
48
 
data/lib/strict/method.rb CHANGED
@@ -8,9 +8,9 @@ module Strict
8
8
  mod.singleton_class.extend(self)
9
9
  end
10
10
 
11
- def sig(&)
11
+ def sig(&block)
12
12
  instance = singleton_class? ? self : singleton_class
13
- instance.instance_variable_set(:@__strict_method_internal_last_sig_configuration, Methods::Dsl.run(&))
13
+ instance.instance_variable_set(:@__strict_method_internal_last_sig_configuration, Methods::Dsl.run(&block))
14
14
  end
15
15
 
16
16
  def strict_class_methods
@@ -4,9 +4,15 @@ module Strict
4
4
  class MethodCallError < Error
5
5
  attr_reader :verifiable_method, :remaining_args, :remaining_kwargs, :invalid_parameters, :missing_parameters
6
6
 
7
- def initialize(verifiable_method:, remaining_args:, remaining_kwargs:, invalid_parameters:, missing_parameters:)
7
+ def initialize(verifiable_method:, remaining_args:, remaining_kwargs:, invalid_parameters:, missing_parameters:) # rubocop:disable Metrics/MethodLength
8
8
  super(
9
- message_from(verifiable_method:, remaining_args:, remaining_kwargs:, invalid_parameters:, missing_parameters:)
9
+ message_from(
10
+ verifiable_method: verifiable_method,
11
+ remaining_args: remaining_args,
12
+ remaining_kwargs: remaining_kwargs,
13
+ invalid_parameters: invalid_parameters,
14
+ missing_parameters: missing_parameters
15
+ )
10
16
  )
11
17
 
12
18
  @verifiable_method = verifiable_method
@@ -5,7 +5,13 @@ module Strict
5
5
  attr_reader :verifiable_method, :missing_parameters, :additional_parameters
6
6
 
7
7
  def initialize(verifiable_method:, missing_parameters:, additional_parameters:)
8
- super(message_from(verifiable_method:, missing_parameters:, additional_parameters:))
8
+ super(
9
+ message_from(
10
+ verifiable_method: verifiable_method,
11
+ missing_parameters: missing_parameters,
12
+ additional_parameters: additional_parameters
13
+ )
14
+ )
9
15
 
10
16
  @verifiable_method = verifiable_method
11
17
  @missing_parameters = missing_parameters
@@ -5,7 +5,7 @@ module Strict
5
5
  attr_reader :verifiable_method, :value
6
6
 
7
7
  def initialize(verifiable_method:, value:)
8
- super(message_from(verifiable_method:, value:))
8
+ super(message_from(verifiable_method: verifiable_method, value: value))
9
9
 
10
10
  @verifiable_method = verifiable_method
11
11
  @value = value
@@ -4,9 +4,9 @@ module Strict
4
4
  module Methods
5
5
  class Dsl < BasicObject
6
6
  class << self
7
- def run(&)
7
+ def run(&block)
8
8
  dsl = new
9
- dsl.instance_eval(&)
9
+ dsl.instance_eval(&block)
10
10
  ::Strict::Methods::Configuration.new(
11
11
  parameters: dsl.__strict_dsl_internal_parameters.values,
12
12
  returns: dsl.__strict_dsl_internal_returns
@@ -11,7 +11,7 @@ module Strict
11
11
  attr_reader :parameter_name
12
12
 
13
13
  def initialize(parameter_name:)
14
- super(message_from(parameter_name:))
14
+ super(message_from(parameter_name: parameter_name))
15
15
 
16
16
  @parameter_name = parameter_name
17
17
  end
@@ -47,7 +47,11 @@ module Strict
47
47
 
48
48
  missing_parameters = expected_parameters - defined_parameters
49
49
  additional_parameters = defined_parameters - expected_parameters
50
- raise Strict::MethodDefinitionError.new(verifiable_method: self, missing_parameters:, additional_parameters:)
50
+ raise Strict::MethodDefinitionError.new(
51
+ verifiable_method: self,
52
+ missing_parameters: missing_parameters,
53
+ additional_parameters: additional_parameters
54
+ )
51
55
  end
52
56
 
53
57
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/BlockLength
@@ -113,8 +117,8 @@ module Strict
113
117
  verifiable_method: self,
114
118
  remaining_args: args,
115
119
  remaining_kwargs: kwargs,
116
- invalid_parameters:,
117
- missing_parameters:
120
+ invalid_parameters: invalid_parameters,
121
+ missing_parameters: missing_parameters
118
122
  )
119
123
  end
120
124
  end
@@ -124,7 +128,7 @@ module Strict
124
128
  value = returns.coerce(value)
125
129
  return if returns.valid?(value)
126
130
 
127
- raise Strict::MethodReturnError.new(verifiable_method: self, value:)
131
+ raise Strict::MethodReturnError.new(verifiable_method: self, value: value)
128
132
  end
129
133
 
130
134
  private
@@ -10,7 +10,12 @@ module Strict
10
10
  raise ArgumentError, "Only one of 'default', 'default_value', or 'default_generator' can be provided"
11
11
  end
12
12
 
13
- new(name: name.to_sym, validator:, default_generator: make_default_generator(**defaults), coercer: coerce)
13
+ new(
14
+ name: name.to_sym,
15
+ validator: validator,
16
+ default_generator: make_default_generator(**defaults),
17
+ coercer: coerce
18
+ )
14
19
  end
15
20
 
16
21
  private
data/lib/strict/return.rb CHANGED
@@ -4,7 +4,7 @@ module Strict
4
4
  class Return
5
5
  class << self
6
6
  def make(validator = Validators::Anything.instance, coerce: false)
7
- new(validator:, coercer: coerce)
7
+ new(validator: validator, coercer: coerce)
8
8
  end
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Strict
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
data/strict.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Strictly define a contract for your objects and methods"
12
12
  spec.homepage = "https://github.com/kylekthompson/strict"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.1.2"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strict
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Thompson
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".rubocop.yml"
147
+ - ".tool-versions"
147
148
  - CHANGELOG.md
148
149
  - CODE_OF_CONDUCT.md
149
150
  - Gemfile
@@ -211,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
212
  requirements:
212
213
  - - ">="
213
214
  - !ruby/object:Gem::Version
214
- version: 3.1.2
215
+ version: 3.0.0
215
216
  required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  requirements:
217
218
  - - ">="
218
219
  - !ruby/object:Gem::Version
219
220
  version: '0'
220
221
  requirements: []
221
- rubygems_version: 3.3.7
222
+ rubygems_version: 3.2.3
222
223
  signing_key:
223
224
  specification_version: 4
224
225
  summary: Strictly define a contract for your objects and methods