activemodel 3.0.1 → 3.0.2

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.
data/CHANGELOG CHANGED
@@ -1,6 +1,12 @@
1
+ *Rails 3.0.2 (November 15, 2010)*
2
+
3
+ * No changes
4
+
5
+
1
6
  *Rails 3.0.1 (October 15, 2010)*
2
7
 
3
- * No Changes, just a version bump.
8
+ * No changes
9
+
4
10
 
5
11
  *Rails 3.0.0 (August 29, 2010)*
6
12
 
@@ -24,7 +24,7 @@
24
24
  activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
25
25
  $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
26
26
  require 'active_support'
27
-
27
+ require 'active_model/version'
28
28
 
29
29
  module ActiveModel
30
30
  extend ActiveSupport::Autoload
@@ -46,7 +46,6 @@ module ActiveModel
46
46
  autoload :Serialization
47
47
  autoload :TestCase
48
48
  autoload :Translation
49
- autoload :VERSION
50
49
  autoload :Validations
51
50
  autoload :Validator
52
51
 
@@ -289,8 +289,8 @@ module ActiveModel
289
289
  end
290
290
 
291
291
  defaults = @base.class.lookup_ancestors.map do |klass|
292
- [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.attributes.#{attribute}.#{type}",
293
- :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.#{type}" ]
292
+ [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}",
293
+ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.#{type}" ]
294
294
  end
295
295
 
296
296
  defaults << options.delete(:message)
@@ -2,7 +2,7 @@ require 'active_support/inflector'
2
2
 
3
3
  module ActiveModel
4
4
  class Name < String
5
- attr_reader :singular, :plural, :element, :collection, :partial_path
5
+ attr_reader :singular, :plural, :element, :collection, :partial_path, :i18n_key
6
6
  alias_method :cache_key, :collection
7
7
 
8
8
  def initialize(klass)
@@ -14,6 +14,7 @@ module ActiveModel
14
14
  @human = ActiveSupport::Inflector.humanize(@element).freeze
15
15
  @collection = ActiveSupport::Inflector.tableize(self).freeze
16
16
  @partial_path = "#{@collection}/#{@element}".freeze
17
+ @i18n_key = ActiveSupport::Inflector.underscore(self).tr('/', '.').to_sym
17
18
  end
18
19
 
19
20
  # Transform the model name into a more humane format, using I18n. By default,
@@ -27,7 +28,7 @@ module ActiveModel
27
28
  @klass.respond_to?(:i18n_scope)
28
29
 
29
30
  defaults = @klass.lookup_ancestors.map do |klass|
30
- klass.model_name.underscore.to_sym
31
+ klass.model_name.i18n_key
31
32
  end
32
33
 
33
34
  defaults << options.delete(:default) if options[:default]
@@ -51,6 +52,9 @@ module ActiveModel
51
52
  # BookCover.model_name # => "BookCover"
52
53
  # BookCover.model_name.human # => "Book cover"
53
54
  #
55
+ # BookCover.model_name.i18n_key # => "book_cover"
56
+ # BookModule::BookCover.model_name.i18n_key # => "book_module.book_cover"
57
+ #
54
58
  # Providing the functionality that ActiveModel::Naming provides in your object
55
59
  # is required to pass the Active Model Lint test. So either extending the provided
56
60
  # method below, or rolling your own is required..
@@ -54,11 +54,13 @@ module ActiveModel
54
54
  #
55
55
  # person = Person.new
56
56
  # person.serializable_hash # => {"name"=>nil}
57
+ # person.as_json # => {"name"=>nil}
57
58
  # person.to_json # => "{\"name\":null}"
58
59
  # person.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
59
60
  #
60
61
  # person.name = "Bob"
61
62
  # person.serializable_hash # => {"name"=>"Bob"}
63
+ # person.as_json # => {"name"=>"Bob"}
62
64
  # person.to_json # => "{\"name\":\"Bob\"}"
63
65
  # person.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
64
66
  #
@@ -67,14 +69,14 @@ module ActiveModel
67
69
  def serializable_hash(options = nil)
68
70
  options ||= {}
69
71
 
70
- options[:only] = Array.wrap(options[:only]).map { |n| n.to_s }
71
- options[:except] = Array.wrap(options[:except]).map { |n| n.to_s }
72
+ only = Array.wrap(options[:only]).map(&:to_s)
73
+ except = Array.wrap(options[:except]).map(&:to_s)
72
74
 
73
75
  attribute_names = attributes.keys.sort
74
- if options[:only].any?
75
- attribute_names &= options[:only]
76
- elsif options[:except].any?
77
- attribute_names -= options[:except]
76
+ if only.any?
77
+ attribute_names &= only
78
+ elsif except.any?
79
+ attribute_names -= except
78
80
  end
79
81
 
80
82
  method_names = Array.wrap(options[:methods]).inject([]) do |methods, name|
@@ -79,18 +79,16 @@ module ActiveModel
79
79
  # "title": "Welcome to the weblog"},
80
80
  # {"comments": [{"body": "Don't think too hard"}],
81
81
  # "title": "So I was thinking"}]}
82
- def encode_json(encoder)
83
- hash = serializable_hash(encoder.options)
82
+
83
+ def as_json(options = nil)
84
+ hash = serializable_hash(options)
85
+
84
86
  if include_root_in_json
85
- custom_root = encoder.options && encoder.options[:root]
87
+ custom_root = options && options[:root]
86
88
  hash = { custom_root || self.class.model_name.element => hash }
87
89
  end
88
90
 
89
- ActiveSupport::JSON.encode(hash)
90
- end
91
-
92
- def as_json(options = nil)
93
- self
91
+ hash
94
92
  end
95
93
 
96
94
  def from_json(json)
@@ -17,7 +17,7 @@ module ActiveModel
17
17
 
18
18
  def initialize(name, serializable, raw_value=nil)
19
19
  @name, @serializable = name, serializable
20
- @value = value || @serializable.send(name)
20
+ @value = raw_value || @serializable.send(name)
21
21
  @type = compute_type
22
22
  end
23
23
 
@@ -44,7 +44,7 @@ module ActiveModel
44
44
  # Specify +options+ with additional translating options.
45
45
  def human_attribute_name(attribute, options = {})
46
46
  defaults = lookup_ancestors.map do |klass|
47
- :"#{self.i18n_scope}.attributes.#{klass.model_name.underscore}.#{attribute}"
47
+ :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
48
48
  end
49
49
 
50
50
  defaults << :"attributes.#{attribute}"
@@ -100,7 +100,7 @@ module ActiveModel
100
100
  # validate :must_be_friends
101
101
  #
102
102
  # def must_be_friends
103
- # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
103
+ # errors.add(:base, "Must be friends to leave a comment") unless commenter.friend_of?(commentee)
104
104
  # end
105
105
  # end
106
106
  #
@@ -114,7 +114,7 @@ module ActiveModel
114
114
  # end
115
115
  #
116
116
  # def must_be_friends
117
- # errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
117
+ # errors.add(:base, ("Must be friends to leave a comment") unless commenter.friend_of?(commentee)
118
118
  # end
119
119
  # end
120
120
  #
@@ -7,7 +7,7 @@ module ActiveModel #:nodoc:
7
7
  # == Active Model Validator
8
8
  #
9
9
  # A simple base class that can be used along with
10
- # +ActiveModel::Validations::ClassMethods.validates_with+
10
+ # ActiveModel::Validations::ClassMethods.validates_with
11
11
  #
12
12
  # class Person
13
13
  # include ActiveModel::Validations
@@ -42,7 +42,7 @@ module ActiveModel #:nodoc:
42
42
  # end
43
43
  # end
44
44
  #
45
- # To cause a validation error, you must add to the <tt>record<tt>'s errors directly
45
+ # To cause a validation error, you must add to the <tt>record</tt>'s errors directly
46
46
  # from within the validators message
47
47
  #
48
48
  # class MyValidator < ActiveModel::Validator
@@ -2,8 +2,8 @@ module ActiveModel
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 1
6
-
5
+ TINY = 2
6
+
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 3
7
8
  - 0
8
- - 1
9
- version: 3.0.1
9
+ - 2
10
+ version: 3.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Heinemeier Hansson
@@ -14,30 +15,34 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-15 00:00:00 +13:00
18
+ date: 2010-11-15 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activesupport
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 3
29
32
  - 0
30
- - 1
31
- version: 3.0.1
33
+ - 2
34
+ version: 3.0.2
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: builder
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ~>
40
44
  - !ruby/object:Gem::Version
45
+ hash: 15
41
46
  segments:
42
47
  - 2
43
48
  - 1
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: i18n
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ~>
54
60
  - !ruby/object:Gem::Version
61
+ hash: 13
55
62
  segments:
56
63
  - 0
57
64
  - 4
@@ -115,25 +122,29 @@ rdoc_options: []
115
122
  require_paths:
116
123
  - lib
117
124
  required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
118
126
  requirements:
119
127
  - - ">="
120
128
  - !ruby/object:Gem::Version
129
+ hash: 57
121
130
  segments:
122
131
  - 1
123
132
  - 8
124
133
  - 7
125
134
  version: 1.8.7
126
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
127
137
  requirements:
128
138
  - - ">="
129
139
  - !ruby/object:Gem::Version
140
+ hash: 3
130
141
  segments:
131
142
  - 0
132
143
  version: "0"
133
144
  requirements: []
134
145
 
135
146
  rubyforge_project: activemodel
136
- rubygems_version: 1.3.6
147
+ rubygems_version: 1.3.7
137
148
  signing_key:
138
149
  specification_version: 3
139
150
  summary: A toolkit for building modeling frameworks (part of Rails).