simple_model 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module ErrorHelpers
5
+
6
+ def errors?
7
+ !self.errors.nil? && !self.errors.empty?
8
+ end
9
+
10
+ def errors_for_flash
11
+ error_string = "<div id='smErrorExplanation'>#{self.errors.count} errors prevented saving.</div>"
12
+ self.errors.full_messages.each do |m|
13
+ error_string << "<div>#{m}</div>"
14
+ end
15
+ error_string
16
+ end
17
+
18
+ def errors_to_s
19
+ error_string = ""
20
+ self.errors.full_messages.each do |m|
21
+ error_string << "#{m} "
22
+ end
23
+ error_string
24
+ end
25
+
26
+ end
@@ -1,23 +1,20 @@
1
1
  module SimpleModel
2
2
 
3
3
  module Errors
4
+ include ErrorHelpers
5
+
4
6
  def errors
5
7
  @errors ||= ErrorsHash.new
6
8
  @errors
7
9
  end
8
10
 
9
-
10
11
  def valid?
11
12
  self.errors.clear if errors
12
13
  validate
13
14
  self.errors.blank? || self.errors.empty?
14
15
  end
15
16
 
16
- def errors?
17
- !self.errors.nil? && !errors.empty?
18
- end
19
-
20
-
17
+
21
18
  def errors_on(attr)
22
19
  self.valid?
23
20
  [self.errors.on(attr.to_s)].flatten.compact
@@ -25,26 +22,10 @@ module SimpleModel
25
22
 
26
23
  alias :error_on :errors_on
27
24
 
28
- def errors_to_s
29
- error_string = ""
30
- self.errors.full_messages.each do |m|
31
- error_string << "#{m} "
32
- end
33
- error_string
34
- end
35
-
36
25
  def validate
37
26
  # Override to implement validation
38
27
  end
39
28
 
40
- def errors_for_flash
41
- error_string = "<div id='smErrorExplanation'>#{errors.count} errors prevented saving.</div>"
42
- errors.full_messages.each do |m|
43
- error_string << "<div>#{m}</div>"
44
- end
45
- error_string
46
- end
47
-
48
29
  class ErrorsHash
49
30
  attr_accessor :errors
50
31
  def initialize
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/simple_model.rb CHANGED
@@ -3,6 +3,7 @@ module SimpleModel
3
3
  autoload :ExtendCore, "simple_model/extend_core"
4
4
  autoload :Attributes, "simple_model/attributes"
5
5
  autoload :Errors, "simple_model/errors"
6
+ autoloan :ErrorHelpers, "simple_model/error_helpers"
6
7
  autoload :Validation, "simple_model/validation"
7
8
 
8
9
  # require active_model if available
@@ -14,6 +15,7 @@ module SimpleModel
14
15
 
15
16
  class Base
16
17
  include SimpleModel::Attributes
18
+ include SimpleModel::ErrorHelpers
17
19
  begin
18
20
  include ActiveModel::Validations
19
21
  include ActiveModel::Conversion
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua T Mckinney
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-01 00:00:00 -06:00
17
+ date: 2011-01-02 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - lib/simple_model.rb
52
52
  - lib/simple_model/attributes.rb
53
+ - lib/simple_model/error_helpers.rb
53
54
  - lib/simple_model/errors.rb
54
55
  - lib/simple_model/extend_core.rb
55
56
  - lib/simple_model/validation.rb