koine-attributes 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 4861f47589ca3917acd1004bfa66db499eda711f
4
- data.tar.gz: 1d5f6a2798c9e655b5fcd4659f65cb1d92ff2683
3
+ metadata.gz: 177452f3f12545dbcaf9a2b57043de1f2efb0d93
4
+ data.tar.gz: 52749eb82a9d367a7b2a2a12298fa1cc6c072770
5
5
  SHA512:
6
- metadata.gz: 05b50951cb2f648ae979f2c23a7c09f17b442c23ceca28e98fe11e34e1cd25906b4e920ce056b3c9144cad36b719b33fe66d87ab56a19fdaa4c4431efd85e44f
7
- data.tar.gz: db69bb585e013ed1f1ea95e05c6b550011864e79f2e3b687535bab52a3e6f45fc0dbee50c81a8a5ca684bebeb3cead9dcce929b1e4c43f2a88aa5f31c5e03117
6
+ metadata.gz: 94d847fb964cbed0f0c6889c8737e133a4cc9c369dafc4d4b2403634998afff288c8ea648855ab79f53f388139248a45344c7b9d3d35d3d5697a9466caa6dabd
7
+ data.tar.gz: 1d88d2820b0b64408e4c53fd1da2310afd84c32b692c8a2ad0f95ec5d2aa63426c78e40119fd90d241e1452736dbb1f1538e1305126cf65328fb6d474724ced2
data/README.md CHANGED
@@ -11,7 +11,6 @@ Yes, there are [so many alternative solutions already](#alternative-solutions)!
11
11
  [![Issue Count](https://codeclimate.com/github/mjacobus/koine-attributes/badges/issue_count.svg)](https://codeclimate.com/github/mjacobus/koine-attributes)
12
12
 
13
13
  [![Gem Version](https://badge.fury.io/rb/koine-attributes.svg)](https://badge.fury.io/rb/koine-attributes)
14
- [![Dependency Status](https://gemnasium.com/badges/github.com/mjacobus/koine-attributes.svg)](https://gemnasium.com/github.com/mjacobus/koine-attributes)
15
14
 
16
15
  ## Installation
17
16
 
@@ -1,6 +1,7 @@
1
1
  require 'koine/attributes/version'
2
2
  require 'koine/attributes/adapter/base'
3
- require 'koine/attributes/argument_error'
3
+ require 'koine/attributes/invalid_attribute_error'
4
+ require 'koine/attributes/invalid_attributes_error'
4
5
 
5
6
  # provides the following API
6
7
  #
@@ -5,7 +5,7 @@ module Koine
5
5
  attr_accessor :attribute_name
6
6
 
7
7
  def initialize
8
- @attribute_name = 'AnonymousAttribute'
8
+ @attribute_name = 'annonymous_attribute_name'
9
9
  end
10
10
 
11
11
  def coerce(value)
@@ -40,7 +40,7 @@ module Koine
40
40
  return @nil_value.respond_to?(:call) ? @nil_value.call : @nil_value
41
41
  end
42
42
 
43
- raise ArgumentError, 'Cannot be nil', attribute_name
43
+ raise_error('Cannot be nil')
44
44
  end
45
45
 
46
46
  def coerce_not_nil(_value)
@@ -61,7 +61,11 @@ module Koine
61
61
  def wrap_errors
62
62
  yield
63
63
  rescue StandardError => error
64
- raise Koine::Attributes::ArgumentError.new(error, attribute_name)
64
+ raise_error(error)
65
+ end
66
+
67
+ def raise_error(message)
68
+ raise Koine::Attributes::InvalidAttributeError.new(message, attribute_name)
65
69
  end
66
70
  end
67
71
  end
@@ -31,7 +31,7 @@ module Koine
31
31
  def coerce_not_nil(value)
32
32
  return true if true_values.include?(value)
33
33
  return false if false_values.include?(value)
34
- raise ArgumentError, "Invalid argument '#{value}'"
34
+ raise InvalidAttributeError.new("Invalid argument '#{value}'", attribute_name)
35
35
  end
36
36
  end
37
37
  end
@@ -14,7 +14,7 @@ module Koine
14
14
 
15
15
  def initialize_values(values = {})
16
16
  if !@initializer[:initialize] && !values.empty?
17
- raise ArgumentError, "wrong number of arguments (given #{values.length}, expected 0)"
17
+ raise InvalidAttributesError, "wrong number of arguments (given #{values.length}, expected 0)"
18
18
  end
19
19
 
20
20
  return unless @initializer[:initialize]
@@ -30,7 +30,7 @@ module Koine
30
30
  end
31
31
 
32
32
  unless invalid_attributes.empty?
33
- raise ArgumentError, "Invalid attributes (#{invalid_attributes.join(', ')})"
33
+ raise InvalidAttributesError, "Invalid attributes (#{invalid_attributes.join(', ')})"
34
34
  end
35
35
 
36
36
  values.each do |attribute, value|
@@ -1,17 +1,18 @@
1
1
  module Koine
2
2
  module Attributes
3
- class ArgumentError < ::ArgumentError
3
+ class InvalidAttributeError < ::ArgumentError
4
4
  attr_reader :attribute_name
5
5
 
6
- def initialize(error, attribute_name = nil)
6
+ def initialize(error, attribute_name)
7
7
  @attribute_name = attribute_name
8
8
 
9
9
  if error.is_a?(Exception)
10
- super(error.message)
11
10
  set_backtrace(error.backtrace)
12
- return
11
+ error = error.message
13
12
  end
14
13
 
14
+ error = "#{attribute_name}: #{error}" if attribute_name
15
+
15
16
  super(error)
16
17
  end
17
18
  end
@@ -0,0 +1,6 @@
1
+ module Koine
2
+ module Attributes
3
+ class InvalidAttributesError < ::ArgumentError
4
+ end
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Koine
2
2
  module Attributes
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koine-attributes
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
  - Marcelo Jacobus
@@ -138,10 +138,11 @@ files:
138
138
  - lib/koine/attributes/adapter/string.rb
139
139
  - lib/koine/attributes/adapter/symbol.rb
140
140
  - lib/koine/attributes/adapter/time.rb
141
- - lib/koine/attributes/argument_error.rb
142
141
  - lib/koine/attributes/attributes.rb
143
142
  - lib/koine/attributes/attributes_factory.rb
144
143
  - lib/koine/attributes/hash_helper.rb
144
+ - lib/koine/attributes/invalid_attribute_error.rb
145
+ - lib/koine/attributes/invalid_attributes_error.rb
145
146
  - lib/koine/attributes/version.rb
146
147
  homepage: https://github.com/mjacobus/koine-attributes
147
148
  licenses: