json_record 1.0.8 → 1.1.0.b2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ 1.0.0
2
+ - Initial release
3
+
4
+ 1.0.1
5
+ - Fixed bug where embedded documents couldn't reference the schema until a field was defined
6
+
7
+ 1.0.2
8
+ - Changed EmbeddedDocument to be a module instead of a class to fix inheritance problem with validations
9
+ - Remove key and many methods from EmbeddedDocument in favor of always calling the schema
10
+
11
+ 1.0.3
12
+ - Added before and after validation callbacks on EmbeddedDocument
13
+ - Fixed bug where fields couldn't be set to false
14
+
15
+ 1.0.4
16
+ - Fixed bug with tracking changes when initializing an EmbeddedDocument.
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.
21
+
22
+ 1.0.6
23
+ - Allow EmbeddedDocument.new to call all accessors and not just those defined in the JSON schema.
24
+ - Allow getting and setting json attributes with [] and []=
25
+
26
+ 1.0.7
27
+ - Added attributes= to EmbeddedDocument for mass attribute assignment
28
+ - Changed deserialized Json values to go through setter methods instead of being directly set
29
+
30
+ 1.0.8
31
+ - Fix Rakefile so it loads even without rspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Brian Durand
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.8
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'json_record'
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{json_record}
8
+ s.version = "1.1.0.b2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brian Durand"]
12
+ s.date = %q{2010-04-06}
13
+ s.email = %q{brian@embellishedvisions.com}
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ "CHANGE_LOG",
19
+ "MIT_LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "init.rb",
24
+ "json_record.gemspec",
25
+ "lib/json_record.rb",
26
+ "lib/json_record/attribute_methods.rb",
27
+ "lib/json_record/embedded_document.rb",
28
+ "lib/json_record/embedded_document_array.rb",
29
+ "lib/json_record/field_definition.rb",
30
+ "lib/json_record/json_field.rb",
31
+ "lib/json_record/schema.rb",
32
+ "lib/json_record/serialized.rb",
33
+ "spec/embedded_document_array_spec.rb",
34
+ "spec/embedded_document_spec.rb",
35
+ "spec/field_definition_spec.rb",
36
+ "spec/serialized_spec.rb",
37
+ "spec/spec_helper.rb",
38
+ "spec/test_models.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/bdurand/json_record}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{ActiveRecord support for mapping complex documents in a single RDBMS row via JSON serialization.}
45
+ s.test_files = [
46
+ "spec/embedded_document_array_spec.rb",
47
+ "spec/embedded_document_spec.rb",
48
+ "spec/field_definition_spec.rb",
49
+ "spec/serialized_spec.rb",
50
+ "spec/spec_helper.rb",
51
+ "spec/test_models.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
60
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
61
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
64
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
65
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<activerecord>, [">= 3.0.0.beta2"])
69
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
70
+ s.add_dependency(%q<jeweler>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -37,7 +37,7 @@ module JsonRecord
37
37
  if changes.include?(field.name)
38
38
  changes.delete(field.name) if converted_value == changes[field.name]
39
39
  else
40
- old_value = (old_value.clone rescue old_value) unless old_value.nil? || old_value.is_a?(Numeric) || old_value.is_a?(Symbol) || old_value.is_a?(TrueClass) || old_value.is_a?(FalseClass)
40
+ old_value = (old_value.clone rescue old_value) unless old_value.nil?
41
41
  changes[field.name] = old_value
42
42
  end
43
43
  end
@@ -139,10 +139,6 @@ module JsonRecord
139
139
  @json_attributes.to_json(*args)
140
140
  end
141
141
 
142
- def to_hash
143
- @json_attributes
144
- end
145
-
146
142
  def eql? (val)
147
143
  val.class == self.class && val.attributes == attributes && val.parent == parent
148
144
  end
@@ -151,10 +147,6 @@ module JsonRecord
151
147
  eql?(val)
152
148
  end
153
149
 
154
- def equal? (val)
155
- eql?(val)
156
- end
157
-
158
150
  def hash
159
151
  attributes.hash + parent.hash
160
152
  end
@@ -22,13 +22,7 @@ module JsonRecord
22
22
 
23
23
  # Get the default value.
24
24
  def default
25
- if @default.nil?
26
- nil
27
- elsif @default.is_a?(Numeric) || @default.is_a?(Symbol) || @default.is_a?(TrueClass) || @default.is_a?(FalseClass)
28
- @default
29
- else
30
- @default.dup rescue @default
31
- end
25
+ (@default.dup rescue @default )if @default
32
26
  end
33
27
 
34
28
  # Indicates the field is multivalued.
@@ -78,8 +72,6 @@ module JsonRecord
78
72
  elsif @type == Hash
79
73
  raise ArgumentError.new("#{name} must be a Hash") unless val.is_a?(Hash)
80
74
  return val
81
- elsif @type == BigDecimal
82
- return BigDecimal.new(val.to_s)
83
75
  else
84
76
  if val.is_a?(@type)
85
77
  val
@@ -94,12 +94,6 @@ describe JsonRecord::Serialized do
94
94
  model.strings.should == ["a", "b"]
95
95
  end
96
96
 
97
- it "should convert values to BigDecimal" do
98
- model = JsonRecord::Test::Model.new
99
- model.price = '5.55'
100
- model.price.should == BigDecimal.new('5.55')
101
- end
102
-
103
97
  it "should convert a hash to an embedded document" do
104
98
  model = JsonRecord::Test::Model.new
105
99
  model.primary_trait = {:name => "thing", :value => "stuff"}
@@ -151,7 +145,6 @@ describe JsonRecord::Serialized do
151
145
  JsonRecord::Test::Model.new.attributes.should == {
152
146
  "name"=>nil,
153
147
  "price"=>nil,
154
- "ratio"=>nil,
155
148
  "string_field"=>nil,
156
149
  "verified_at"=>nil,
157
150
  "viewed_at"=>nil,
@@ -161,7 +154,6 @@ describe JsonRecord::Serialized do
161
154
  "field_4"=>nil,
162
155
  "field_5"=>nil,
163
156
  "unit_price"=>nil,
164
- "unit_ratio"=>nil,
165
157
  "traits"=>[],
166
158
  "value"=>0,
167
159
  "strings"=>[],
@@ -474,12 +466,4 @@ describe JsonRecord::Serialized do
474
466
  model.unit_price = 1.2253
475
467
  model.unit_price.should == 1.23
476
468
  end
477
-
478
- it "should blow up if the json column doesn't exist" do
479
- lambda{JsonRecord::Test::Broken.new(:name => "Test", :value => "Moo")}.should raise_error
480
- end
481
-
482
- it "should blow up if trying to set a json attribute hasn't been defined" do
483
- lambda{model = JsonRecord::Test::Model.new(:undefined_attribute => "what?")}.should raise_error
484
- end
485
469
  end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
- active_record_version = ENV["ACTIVE_RECORD_VERSION"] || [">=2.2.2", "<=2.9.9"]
3
+ active_record_version = ENV["ACTIVE_RECORD_VERSION"] || [">= 2.2.2", "< 3.0"]
4
4
  active_record_version = [active_record_version] unless active_record_version.is_a?(Array)
5
5
  gem 'activerecord', *active_record_version
6
6
 
@@ -59,7 +59,6 @@ module JsonRecord
59
59
  schema.key :name, String, :required => true, :length => 15
60
60
  schema.key :value, Integer, :default => 0
61
61
  schema.key :price, Float
62
- schema.key :ratio, BigDecimal
63
62
  schema.key :verified, Boolean
64
63
  schema.key :when, Date
65
64
  schema.key :verified_at, Time
@@ -78,7 +77,6 @@ module JsonRecord
78
77
  schema.key :field_4, :length => (4..15)
79
78
  schema.key :field_5, :length => {:minimum => 5}
80
79
  schema.key :unit_price, Float
81
- schema.key :unit_ratio, BigDecimal
82
80
  end
83
81
 
84
82
  def unit_price
@@ -99,13 +97,5 @@ module JsonRecord
99
97
  schema.key :another_field
100
98
  end
101
99
  end
102
-
103
- class Broken < ActiveRecord::Base
104
- set_table_name :models
105
- serialize_to_json(:no_such_column) do |schema|
106
- schema.key :name, String
107
- schema.key :value, String
108
- end
109
- end
110
100
  end
111
101
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_record
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
4
+ prerelease: true
6
5
  segments:
7
6
  - 1
7
+ - 1
8
8
  - 0
9
- - 8
10
- version: 1.0.8
9
+ - b2
10
+ version: 1.1.0.b2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Durand
@@ -15,50 +15,45 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-31 00:00:00 -05:00
18
+ date: 2010-04-06 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
- - 2
32
- - 2
33
- - 2
34
- version: 2.2.2
29
+ - 3
30
+ - 0
31
+ - 0
32
+ - beta2
33
+ version: 3.0.0.beta2
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rspec
39
38
  prerelease: false
40
39
  requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 13
46
43
  segments:
47
44
  - 1
48
- - 2
49
- - 9
50
- version: 1.2.9
45
+ - 3
46
+ - 0
47
+ version: 1.3.0
51
48
  type: :development
52
49
  version_requirements: *id002
53
50
  - !ruby/object:Gem::Dependency
54
51
  name: jeweler
55
52
  prerelease: false
56
53
  requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
54
  requirements:
59
55
  - - ">="
60
56
  - !ruby/object:Gem::Version
61
- hash: 3
62
57
  segments:
63
58
  - 0
64
59
  version: "0"
@@ -73,8 +68,13 @@ extensions: []
73
68
  extra_rdoc_files:
74
69
  - README.rdoc
75
70
  files:
71
+ - CHANGE_LOG
72
+ - MIT_LICENSE
76
73
  - README.rdoc
77
74
  - Rakefile
75
+ - VERSION
76
+ - init.rb
77
+ - json_record.gemspec
78
78
  - lib/json_record.rb
79
79
  - lib/json_record/attribute_methods.rb
80
80
  - lib/json_record/embedded_document.rb
@@ -99,27 +99,25 @@ rdoc_options:
99
99
  require_paths:
100
100
  - lib
101
101
  required_ruby_version: !ruby/object:Gem::Requirement
102
- none: false
103
102
  requirements:
104
103
  - - ">="
105
104
  - !ruby/object:Gem::Version
106
- hash: 3
107
105
  segments:
108
106
  - 0
109
107
  version: "0"
110
108
  required_rubygems_version: !ruby/object:Gem::Requirement
111
- none: false
112
109
  requirements:
113
- - - ">="
110
+ - - ">"
114
111
  - !ruby/object:Gem::Version
115
- hash: 3
116
112
  segments:
117
- - 0
118
- version: "0"
113
+ - 1
114
+ - 3
115
+ - 1
116
+ version: 1.3.1
119
117
  requirements: []
120
118
 
121
119
  rubyforge_project:
122
- rubygems_version: 1.3.7
120
+ rubygems_version: 1.3.6
123
121
  signing_key:
124
122
  specification_version: 3
125
123
  summary: ActiveRecord support for mapping complex documents in a single RDBMS row via JSON serialization.