json_record 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGE_LOG CHANGED
@@ -15,3 +15,6 @@
15
15
  1.0.4
16
16
  - Fixed bug with tracking changes when initializing an EmbeddedDocument.
17
17
  - Removed tracking changes of keys that are EmbeddedDocuments
18
+
19
+ 1.0.5
20
+ - Fixed bug with initializing new EmbeddedDocumentArray with the proper parent when there is no data to deserialize.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{json_record}
8
- s.version = "1.0.4"
8
+ s.version = "1.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Durand"]
12
- s.date = %q{2010-02-22}
12
+ s.date = %q{2010-02-23}
13
13
  s.email = %q{brian@embellishedvisions.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -26,7 +26,7 @@ module JsonRecord
26
26
  @attributes = {}
27
27
  @schemas.each do |schema|
28
28
  schema.fields.values.each do |field|
29
- @attributes[field.name] = field.multivalued? ? EmbeddedDocumentArray.new(field.type, self) : field.default
29
+ @attributes[field.name] = field.multivalued? ? EmbeddedDocumentArray.new(field.type, @record) : field.default
30
30
  end
31
31
  end
32
32
 
@@ -12,7 +12,7 @@ module JsonRecord
12
12
  end
13
13
 
14
14
  # Define a single valued field in the schema.
15
- # The first argument should be the field name. This must be unique for the class accross all attributes.
15
+ # The first argument is the field name. This must be unique for the class accross all attributes.
16
16
  #
17
17
  # The optional second argument can be used to specify the class of the field values. It will default to
18
18
  # String if not specified. Valid types are String, Integer, Float, Date, Time, DateTime, Boolean, Array, Hash,
@@ -37,6 +37,18 @@ module JsonRecord
37
37
  define_json_accessor(field, json_field_name)
38
38
  end
39
39
 
40
+ # Define a multi valued field in the schema.
41
+ # The first argument is the field name. This must be unique for the class accross all attributes.
42
+ #
43
+ # The optional second argument should be the class of field values. This class must include EmbeddedDocument.
44
+ # If it is not specified, the class name will be guessed from the field name.
45
+ #
46
+ # The last argument can be :unique => field_name which is used to indicate that the values in the field
47
+ # must have unique values in the indicated field name.
48
+ #
49
+ # The value of the field will always be an EmbeddedDocumentArray and adding and removing values is as
50
+ # simple as appending them to the array. You can also call the build method on the array to keep the syntax the
51
+ # same as when dealing with ActiveRecord has_many associations.
40
52
  def many (name, *args)
41
53
  name = name.to_s
42
54
  options = args.extract_options!
@@ -49,7 +61,7 @@ module JsonRecord
49
61
 
50
62
  private
51
63
 
52
- def add_json_validations (field, options)
64
+ def add_json_validations (field, options) #:nodoc:
53
65
  @klass.validates_presence_of(field.name) if options[:required]
54
66
  @klass.validates_format_of(field.name, :with => options[:format], :allow_blank => true) if options[:format]
55
67
 
@@ -110,7 +122,7 @@ module JsonRecord
110
122
  end
111
123
  end
112
124
 
113
- def define_json_accessor (field, json_field_name)
125
+ def define_json_accessor (field, json_field_name) #:nodoc:
114
126
  @klass.send(:define_method, field.name) {read_json_attribute(json_field_name, field)}
115
127
  @klass.send(:define_method, "#{field.name}?") {!!read_json_attribute(json_field_name, field)} if field.type == Boolean
116
128
  @klass.send(:define_method, "#{field.name}=") {|val| write_json_attribute(json_field_name, field, val)}
@@ -122,7 +134,7 @@ module JsonRecord
122
134
  end
123
135
  end
124
136
 
125
- def define_many_json_accessor (field, json_field_name)
137
+ def define_many_json_accessor (field, json_field_name) #:nodoc:
126
138
  @klass.send(:define_method, field.name) {self.read_json_attribute(json_field_name, field)}
127
139
  @klass.send(:define_method, "#{field.name}=") {|val| self.write_json_attribute(json_field_name, field, val)}
128
140
  end
@@ -60,12 +60,12 @@ module JsonRecord
60
60
  @json_fields
61
61
  end
62
62
 
63
- def reload_with_serialized_json (*args)
63
+ def reload_with_serialized_json (*args) #:nodoc:
64
64
  @json_fields = nil
65
65
  reload_without_serialized_json(*args)
66
66
  end
67
67
 
68
- def attributes_with_serialized_json
68
+ def attributes_with_serialized_json #:nodoc:
69
69
  attrs = json_attributes.reject{|k,v| !json_field_names.include?(k)}
70
70
  attrs.merge!(attributes_without_serialized_json)
71
71
  json_serialized_fields.keys.each{|name| attrs.delete(name)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-22 00:00:00 -06:00
12
+ date: 2010-02-23 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency