destination_errors 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 1f3a5e8c45326abaec74d12735ed07c34fcb6967
4
- data.tar.gz: 8d1a0884a7e647e46cae1b7f2e6961ce9512f299
3
+ metadata.gz: 707945486ea424f4a1e970e612f4ccfdd707c3b8
4
+ data.tar.gz: f6a93ecd7843317ca5195da41fc418eee1a51c8c
5
5
  SHA512:
6
- metadata.gz: 5fed81c47120851263221c1b7e788a68eab6f408998d136bf1462fd2547c56450963274cda4e8a3a70e2c7e9e4984a25a68480eeeb1e4c83ca8aa4f0c34b70ac
7
- data.tar.gz: b669a0e57adae8765dea6cebfe327ff7814640c46b666148ed34a406b9598d11ce38b395ffd1fe4271f663792097858c87a460b9eb6c987639747aeb6eaba849
6
+ metadata.gz: ccb67dccca62ed177a8ec0a480fdd661ef72d5058d0c63b63717d8d0d6c5d0e3eb04c1161b8aadbf5a0e4eaa4a740b59ec8a4cc27f56a465848409a05f4b9f1b
7
+ data.tar.gz: 6a8cb2ff47ef2eb9d2da2b8f4315663750b7c1d52c2c945b2133e19ec4aded6fdaaede25963ffa389f4336473ca2204a4b9cd90073a6ebc0f446f557ec6fa94b
@@ -1,4 +1,6 @@
1
1
  require "destination_errors/version"
2
+ require "destination_errors/unique_errors"
3
+ require "destination_errors/active_model_integration"
2
4
 
3
5
  #
4
6
  # There are three steps to implementing this module in a class:
@@ -29,16 +31,14 @@ require "destination_errors/version"
29
31
  # end
30
32
  #
31
33
 
32
- require "active_model"
33
-
34
34
  module DestinationErrors
35
35
 
36
36
  def self.included(base)
37
- base.include(ActiveModel::Validations)
38
37
  base.prepend(Initializer)
39
38
  base.extend(ClassMethods)
39
+ base.include(DestinationErrors::ActiveModelIntegration)
40
+ base.include(DestinationErrors::UniqueErrors)
40
41
  base.class_eval do
41
- attr_reader :errors
42
42
  attr_accessor :errors_finalized
43
43
  attr_accessor :surface_errors_on
44
44
  class_attribute :error_surfaces
@@ -47,7 +47,6 @@ module DestinationErrors
47
47
 
48
48
  module Initializer
49
49
  def initialize(*args)
50
- @errors = ActiveModel::Errors.new(self)
51
50
  @surface_errors_on = nil
52
51
  super
53
52
  end
@@ -66,11 +65,6 @@ module DestinationErrors
66
65
  return true
67
66
  end
68
67
 
69
- # Required for ActiveModel::Validations
70
- def read_attribute_for_validation(attr)
71
- send(attr)
72
- end
73
-
74
68
  # dynamically access the surface where errors are being aggregated
75
69
  def error_destination
76
70
  @error_destination = error_destination_is_self? ?
@@ -83,16 +77,6 @@ module DestinationErrors
83
77
  def has_error_surfaces(value)
84
78
  self.error_surfaces = value
85
79
  end
86
-
87
- # Required for ActiveModel::Validations
88
- def human_attribute_name(attr, options = {})
89
- attr
90
- end
91
-
92
- # Required for ActiveModel::Validations
93
- def lookup_ancestors
94
- [self]
95
- end
96
80
  end
97
81
 
98
82
  protected
@@ -119,7 +103,7 @@ module DestinationErrors
119
103
  errors.messages :
120
104
  self.send(surface).errors.messages
121
105
  ).each do |key, message_array|
122
- move_error_to_destination(key, message_array)
106
+ move_error_to_destination(key, *message_array)
123
107
  end
124
108
  end
125
109
  end
@@ -146,21 +130,13 @@ module DestinationErrors
146
130
  surface_errors_on.nil? || !self.send(surface_errors_on)
147
131
  end
148
132
 
149
- def move_error_to_destination(key, message_array)
133
+ def move_error_to_destination(key, *message_array)
150
134
  if error_destination.respond_to?(key)
151
- add_uniquely(key, message_array)
135
+ add_errors_uniquely(key, *message_array)
152
136
  elsif key == :base
153
- add_uniquely(:base, message_array)
137
+ add_errors_uniquely(:base, *message_array)
154
138
  else
155
- add_uniquely(:base, message_array.map {|message| "#{key} #{message}"})
156
- end
157
- end
158
-
159
- def add_uniquely(key, message_array)
160
- message_array.each do |message|
161
- unless error_destination.errors[key].include?(message)
162
- error_destination.errors.add(key, message)
163
- end
139
+ add_errors_uniquely(:base, *message_array.map {|message| "#{key} #{message}"})
164
140
  end
165
141
  end
166
142
 
@@ -0,0 +1,39 @@
1
+ require "active_model"
2
+
3
+ module DestinationErrors
4
+ module ActiveModelIntegration
5
+
6
+ # Required for ActiveModel::Validations
7
+ def read_attribute_for_validation(attr)
8
+ send(attr)
9
+ end
10
+
11
+ def self.included(base)
12
+ base.include(ActiveModel::Validations)
13
+ base.prepend(Initializer)
14
+ base.extend(ClassMethods)
15
+ base.class_eval do
16
+ attr_reader :errors
17
+ end
18
+ end
19
+
20
+ module Initializer
21
+ def initialize(*args)
22
+ @errors = ActiveModel::Errors.new(self)
23
+ super
24
+ end
25
+ end
26
+
27
+ module ClassMethods
28
+ # Required for ActiveModel::Validations
29
+ def human_attribute_name(attr, options = {})
30
+ attr
31
+ end
32
+
33
+ # Required for ActiveModel::Validations
34
+ def lookup_ancestors
35
+ [self]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ module DestinationErrors
2
+ module UniqueErrors
3
+
4
+ def self.included(base)
5
+ base.include(ErrorAggregation)
6
+ end
7
+
8
+ module ErrorAggregation
9
+ def add_errors_uniquely(key, *message_array)
10
+ message_array.each do |message|
11
+ error_destination.errors.add(key, message) unless error_destination.errors[key].include?(message)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module DestinationErrors
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destination_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -100,6 +100,8 @@ files:
100
100
  - bin/setup
101
101
  - destination_errors.gemspec
102
102
  - lib/destination_errors.rb
103
+ - lib/destination_errors/active_model_integration.rb
104
+ - lib/destination_errors/unique_errors.rb
103
105
  - lib/destination_errors/version.rb
104
106
  homepage: https://github.com/trumaker/destination_errors
105
107
  licenses:
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  requirements: []
123
125
  rubyforge_project:
124
- rubygems_version: 2.4.2
126
+ rubygems_version: 2.2.2
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: Mixin providing management of error surfaces within the familiar territory