property 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 2.3.0
2
+
3
+ * Major enhancements
4
+ * Fixed tests and sources for Ruby 1.9
5
+ * Enabled stored columns for serialized properties
6
+
1
7
  == 2.2.0 2011-06-06
2
8
 
3
9
  * Major enhancements
@@ -8,13 +8,25 @@ module Property
8
8
  module Validator
9
9
  NATIVE_TYPES = [Hash, Array, Integer, Float, String, TrueClass, FalseClass, NilClass]
10
10
 
11
- # Should raise an exception if the type is not serializable.
12
- def self.validate(klass)
13
- if NATIVE_TYPES.include?(klass) ||
14
- (klass.respond_to?('json_create') && klass.instance_methods.include?('to_json'))
15
- true
16
- else
17
- raise TypeError.new("Cannot serialize #{klass}. Missing 'self.create_json' and 'to_json' methods.")
11
+ if RUBY_VERSION.to_f > 1.8
12
+ # Should raise an exception if the type is not serializable.
13
+ def self.validate(klass)
14
+ if NATIVE_TYPES.include?(klass) ||
15
+ (klass.respond_to?(:json_create) && klass.instance_methods.include?(:to_json))
16
+ true
17
+ else
18
+ raise TypeError.new("Cannot serialize #{klass}. Missing 'self.create_json' and 'to_json' methods.")
19
+ end
20
+ end
21
+ else
22
+ # Should raise an exception if the type is not serializable.
23
+ def self.validate(klass)
24
+ if NATIVE_TYPES.include?(klass) ||
25
+ (klass.respond_to?('json_create') && klass.instance_methods.include?('to_json'))
26
+ true
27
+ else
28
+ raise TypeError.new("Cannot serialize #{klass}. Missing 'self.create_json' and 'to_json' methods.")
29
+ end
18
30
  end
19
31
  end
20
32
  end
@@ -10,6 +10,11 @@ module Property
10
10
  def default
11
11
  nil
12
12
  end
13
+
14
+ # Used to store serialized properties. Should return the class to serialize.
15
+ def klass
16
+ nil
17
+ end
13
18
 
14
19
  # No supported options yet.
15
20
  def options
@@ -67,7 +67,7 @@ module Property
67
67
  @original_columns = {}
68
68
  stored_columns.each do |column|
69
69
  @original_columns[column.name] = column
70
- add_column(Property::Column.new(column.name, column.default, column.ptype, column.options.merge(:role => self, :orig => column)))
70
+ add_column(Property::Column.new(column.name, column.default, column.klass || column.ptype, column.options.merge(:role => self, :orig => column)))
71
71
  end
72
72
  end
73
73
 
@@ -1,3 +1,3 @@
1
1
  module Property
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
data/property.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property}
8
- s.version = "2.2.0"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Renaud Kern", "Gaspard Bucher"]
12
- s.date = %q{2011-06-06}
12
+ s.date = %q{2012-05-23}
13
13
  s.description = %q{Wrap model properties into a single database column and declare properties from within the model.}
14
14
  s.email = %q{gaspard@teti.ch}
15
15
  s.extra_rdoc_files = [
@@ -72,32 +72,8 @@ Gem::Specification.new do |s|
72
72
  s.homepage = %q{http://zenadmin.org/635}
73
73
  s.require_paths = ["lib"]
74
74
  s.rubyforge_project = %q{property}
75
- s.rubygems_version = %q{1.6.1}
75
+ s.rubygems_version = %q{1.6.2}
76
76
  s.summary = %q{model properties wrap into a single database column}
77
- s.test_files = [
78
- "test/database.rb",
79
- "test/fixtures.rb",
80
- "test/shoulda_macros/index.rb",
81
- "test/shoulda_macros/role.rb",
82
- "test/shoulda_macros/serialization.rb",
83
- "test/test_helper.rb",
84
- "test/unit/property/attribute_test.rb",
85
- "test/unit/property/base_test.rb",
86
- "test/unit/property/column_test.rb",
87
- "test/unit/property/declaration_test.rb",
88
- "test/unit/property/dirty_test.rb",
89
- "test/unit/property/index_complex_test.rb",
90
- "test/unit/property/index_custom_test.rb",
91
- "test/unit/property/index_field_test.rb",
92
- "test/unit/property/index_foreign_test.rb",
93
- "test/unit/property/index_simple_test.rb",
94
- "test/unit/property/role_test.rb",
95
- "test/unit/property/stored_role_test.rb",
96
- "test/unit/property/validation_test.rb",
97
- "test/unit/serialization/json_test.rb",
98
- "test/unit/serialization/marshal_test.rb",
99
- "test/unit/serialization/yaml_test.rb"
100
- ]
101
77
 
102
78
  if s.respond_to? :specification_version then
103
79
  s.specification_version = 3
data/test/fixtures.rb CHANGED
@@ -50,7 +50,6 @@ class Cat
50
50
  end
51
51
  end
52
52
 
53
-
54
53
  class IdxEmployeesString < ActiveRecord::Base
55
54
  end
56
55
 
@@ -3,7 +3,7 @@ module IndexMacros
3
3
  class Client < ActiveRecord::Base
4
4
  set_table_name :employees
5
5
  include Property
6
-
6
+
7
7
  def muse
8
8
  'I am your muse'
9
9
  end
@@ -53,15 +53,15 @@ class Test::Unit::TestCase
53
53
  end
54
54
  end
55
55
  end
56
-
56
+
57
57
  should 'build a group of indices' do
58
58
  assert_equal Hash['ml_string'=>[['poem', nil]], 'integer'=>[['year', nil]]], subject.schema.index_groups
59
59
  end
60
-
60
+
61
61
  should 'build indices array' do
62
- assert_equal [['integer', 'year', nil], ['ml_string', 'poem', nil]], @poet.defined_indices
62
+ assert_equal [['integer', 'year', nil], ['ml_string', 'poem', nil]], @poet.defined_indices.sort{|a,b| a[0] <=> b[0]}
63
63
  end
64
-
64
+
65
65
  should 'only use defined propertys to build indices array' do
66
66
  assert_equal [], subject.schema.defined_indices
67
67
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  class Test::Unit::TestCase
2
3
 
3
4
  def self.should_encode_and_decode_properties
@@ -40,8 +41,13 @@ class Test::Unit::TestCase
40
41
 
41
42
  context 'with ascii 18' do
42
43
  subject do
44
+ if RUBY_VERSION.to_f > 1.8
45
+ str = (1..255).to_a.map{|n| n.chr('utf-8')}.join('') # "AB"
46
+ else
47
+ str = (1..255).to_a.map{|n| n.chr}.join('') # "AB"
48
+ end
43
49
  Property::Properties[
44
- 'string' => (1..255).to_a.map{|n| n.chr}.join('') # "AB"
50
+ 'string' => str
45
51
  ]
46
52
  end
47
53
 
@@ -49,7 +55,7 @@ class Test::Unit::TestCase
49
55
  string = @obj.encode_properties(subject)
50
56
  properties = @obj.decode_properties(string)
51
57
  assert_equal Property::Properties, properties.class
52
- assert_equal subject, properties
58
+ assert_equal subject['string'], properties['string']
53
59
  end
54
60
  end # with ascii 18
55
61
 
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
  require 'fixtures'
3
4
 
@@ -114,20 +115,39 @@ class DeclarationTest < Test::Unit::TestCase
114
115
  assert_kind_of Property::Column, subject.schema.columns['weapon']
115
116
  end
116
117
 
117
- should 'create ruby accessors' do
118
- subject.property.string('weapon')
119
- assert subject.instance_methods.include?('weapon')
120
- assert subject.instance_methods.include?('weapon=')
121
- assert subject.instance_methods.include?('weapon?')
122
- end
118
+ if RUBY_VERSION.to_f > 1.8
119
+ should 'create ruby accessors' do
120
+ subject.property.string('weapon')
121
+ assert subject.instance_methods.include?(:weapon)
122
+ assert subject.instance_methods.include?(:weapon=)
123
+ assert subject.instance_methods.include?(:weapon?)
124
+ end
125
+
126
+ should 'not create accessors for illegal ruby names' do
127
+ bad_names = ['some.thing', 'puts("yo")', '/var/', 'hello darness']
128
+ assert_nothing_raised { subject.property.string bad_names }
129
+ bad_names.each do |bad_name|
130
+ assert !subject.instance_methods.include?(bad_name.to_sym)
131
+ assert !subject.instance_methods.include?(:"#{bad_name}=")
132
+ assert !subject.instance_methods.include?(:"#{bad_name}?")
133
+ end
134
+ end
135
+ else
136
+ should 'create ruby accessors' do
137
+ subject.property.string('weapon')
138
+ assert subject.instance_methods.include?('weapon')
139
+ assert subject.instance_methods.include?('weapon=')
140
+ assert subject.instance_methods.include?('weapon?')
141
+ end
123
142
 
124
- should 'not create accessors for illegal ruby names' do
125
- bad_names = ['some.thing', 'puts("yo")', '/var/', 'hello darness']
126
- assert_nothing_raised { subject.property.string bad_names }
127
- bad_names.each do |bad_name|
128
- assert !subject.instance_methods.include?(bad_name)
129
- assert !subject.instance_methods.include?("#{bad_name}=")
130
- assert !subject.instance_methods.include?("#{bad_name}?")
143
+ should 'not create accessors for illegal ruby names' do
144
+ bad_names = ['some.thing', 'puts("yo")', '/var/', 'hello darness']
145
+ assert_nothing_raised { subject.property.string bad_names }
146
+ bad_names.each do |bad_name|
147
+ assert !subject.instance_methods.include?(bad_name)
148
+ assert !subject.instance_methods.include?("#{bad_name}=")
149
+ assert !subject.instance_methods.include?("#{bad_name}?")
150
+ end
131
151
  end
132
152
  end
133
153
 
@@ -293,7 +313,7 @@ class DeclarationTest < Test::Unit::TestCase
293
313
  end
294
314
 
295
315
  subject.include_role @class
296
- assert_equal %w{language last_name hop age first_name}, subject.schema.column_names
316
+ assert_equal %w{language last_name hop age first_name}.sort, subject.schema.column_names.sort
297
317
  assert subject.has_role?(@class.schema)
298
318
  end
299
319
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
  require 'fixtures'
3
4
 
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
  require 'fixtures'
3
4
 
@@ -20,7 +21,7 @@ class IndexComplexTest < ActiveSupport::TestCase
20
21
  p.string 'name'
21
22
  # only runs if 'age' is not blank
22
23
  p.integer 'age', :index => Proc.new {|r| {'age' => r.age == 0 ? nil : r.age + 10}}
23
- p.string 'gender', :index => Proc.new {|r| {'gender' => r.gender[0]}}, :index_group => :integer
24
+ p.string 'gender', :index => Proc.new {|r| {'gender' => r.gender.ord}}, :index_group => :integer
24
25
  p.string 'lang'
25
26
 
26
27
  p.index(:text) do |r| # r = record
@@ -78,11 +79,11 @@ class IndexComplexTest < ActiveSupport::TestCase
78
79
  int_index = IdxEmployeesInteger.first(:conditions => {:employee_id => person.id, :key => 'age'})
79
80
  assert_equal 44, int_index.value
80
81
  end
81
-
82
+
82
83
  should 'use index_group setting to build values' do
83
84
  person = Person.create('name' => 'Juan', 'lang' => 'es', 'gender' => 'M', 'age' => 34)
84
85
  int_index = IdxEmployeesInteger.first(:conditions => {:employee_id => person.id, :key => 'gender'})
85
- assert_equal "M"[0], int_index.value
86
+ assert_equal ?M.ord, int_index.value
86
87
  end
87
88
 
88
89
  should 'remove blank values built from proc execution' do
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'test_helper'
2
3
  require 'fixtures'
3
4
 
@@ -35,7 +36,7 @@ class IndexSimpleTest < ActiveSupport::TestCase
35
36
  should 'group indices by type' do
36
37
  assert_equal %w{integer special}, subject.index_groups.keys.map(&:to_s).sort
37
38
  end
38
-
39
+
39
40
  should 'not contain duplicates' do
40
41
  assert_equal Hash["special"=>[["name", nil]], "integer"=>[["age", nil]]], subject.index_groups
41
42
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require "test_helper"
2
3
  require 'property/serialization/json'
3
4
 
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require "test_helper"
2
3
  require 'property/serialization/yaml'
3
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 2.2.0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Renaud Kern
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-06 00:00:00 +02:00
19
+ date: 2012-05-23 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -138,30 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements: []
139
139
 
140
140
  rubyforge_project: property
141
- rubygems_version: 1.6.1
141
+ rubygems_version: 1.6.2
142
142
  signing_key:
143
143
  specification_version: 3
144
144
  summary: model properties wrap into a single database column
145
- test_files:
146
- - test/database.rb
147
- - test/fixtures.rb
148
- - test/shoulda_macros/index.rb
149
- - test/shoulda_macros/role.rb
150
- - test/shoulda_macros/serialization.rb
151
- - test/test_helper.rb
152
- - test/unit/property/attribute_test.rb
153
- - test/unit/property/base_test.rb
154
- - test/unit/property/column_test.rb
155
- - test/unit/property/declaration_test.rb
156
- - test/unit/property/dirty_test.rb
157
- - test/unit/property/index_complex_test.rb
158
- - test/unit/property/index_custom_test.rb
159
- - test/unit/property/index_field_test.rb
160
- - test/unit/property/index_foreign_test.rb
161
- - test/unit/property/index_simple_test.rb
162
- - test/unit/property/role_test.rb
163
- - test/unit/property/stored_role_test.rb
164
- - test/unit/property/validation_test.rb
165
- - test/unit/serialization/json_test.rb
166
- - test/unit/serialization/marshal_test.rb
167
- - test/unit/serialization/yaml_test.rb
145
+ test_files: []
146
+