property 2.1.2 → 2.2.0

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/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 2.2.0 2011-06-06
2
+
3
+ * Major enhancements
4
+ * Better support for stored columns and custom type cast.
5
+
1
6
  == 2.1.2 2010-12-04
2
7
 
3
8
  * Major enhancements
@@ -101,7 +101,7 @@ module Property
101
101
  model_attrs[k] = attributes.delete(k)
102
102
  end
103
103
  end
104
-
104
+
105
105
  # Properties validation will add errors on invalid keys.
106
106
  self.properties = attributes
107
107
  self.attributes_without_properties = model_attrs
@@ -59,7 +59,9 @@ module Property
59
59
  alias ptype type
60
60
 
61
61
  def type_cast(value)
62
- if type == :string
62
+ if @caster && val = @caster.type_cast(value)
63
+ val
64
+ elsif type == :string
63
65
  value = value.to_s
64
66
  value.blank? ? nil : value
65
67
  elsif @klass
@@ -78,6 +80,7 @@ module Property
78
80
  def extract_property_options(options)
79
81
  @index = options.delete(:index) || options.delete(:indexed)
80
82
  @role = options.delete(:role)
83
+ @caster= options.delete(:orig)
81
84
  if @index == true
82
85
  @index = (options.delete(:index_group) || ptype).to_s
83
86
  elsif @index.kind_of?(Proc)
@@ -186,7 +186,7 @@ module Property
186
186
  cur_indices.merge!(proc.call(self))
187
187
  end
188
188
  end
189
-
189
+
190
190
  if group_name.kind_of?(Class)
191
191
  # Use a custom indexer
192
192
  group_name.set_property_index(self, cur_indices)
@@ -200,7 +200,7 @@ module Property
200
200
  new_keys = cur_keys - old_keys
201
201
  del_keys = old_keys - cur_keys
202
202
  upd_keys = cur_keys & old_keys
203
-
203
+
204
204
  upd_keys.each do |key|
205
205
  value = cur_indices[key]
206
206
  if value.blank?
@@ -101,7 +101,7 @@ module Property
101
101
 
102
102
  def inspect
103
103
  # "#<#{self.class}:#{sprintf("0x%x", object_id)} #{@name.inspect} @klass = #{@klass.inspect} @defined_columns = #{@defined_columns.inspect}>"
104
- "#<#{self.class}:#{sprintf("0x%x", object_id)} #{defined_columns.keys.inspect}>"
104
+ "#<#{self.class}:'#{name}' #{defined_columns.keys.join(', ')}>"
105
105
  end
106
106
 
107
107
  # List all property columns defined for this role
@@ -16,6 +16,11 @@ module Property
16
16
  {:index => (index.blank? ? nil : index)}
17
17
  end
18
18
 
19
+ # Dummy, can be reimplemented in the class storing the column.
20
+ def type_cast(value)
21
+ nil
22
+ end
23
+
19
24
  private
20
25
  def set_index
21
26
  if index == true
@@ -22,7 +22,7 @@ module Property
22
22
  base.class_eval do
23
23
  after_save :update_columns
24
24
  validates_presence_of :name
25
-
25
+
26
26
  extend ClassMethods
27
27
 
28
28
  def self.new(arg, &block)
@@ -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)))
70
+ add_column(Property::Column.new(column.name, column.default, column.ptype, column.options.merge(:role => self, :orig => column)))
71
71
  end
72
72
  end
73
73
 
@@ -85,7 +85,6 @@ module Property
85
85
  # deleted_columns = stored_column_names - defined_column_names
86
86
 
87
87
  new_columns.each do |name|
88
- ActiveRecord::Base.logger.warn "Creating #{name} column"
89
88
  stored_columns.create(:name => name, :ptype => columns[name].type.to_s)
90
89
  end
91
90
 
@@ -1,3 +1,3 @@
1
1
  module Property
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.0'
3
3
  end
data/property.gemspec CHANGED
@@ -1,108 +1,105 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property}
8
- s.version = "2.1.2"
8
+ s.version = "2.2.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{2010-12-04}
12
+ s.date = %q{2011-06-06}
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 = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "History.txt",
21
- "MIT-LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "generators/property/property_generator.rb",
25
- "lib/property.rb",
26
- "lib/property/attribute.rb",
27
- "lib/property/base.rb",
28
- "lib/property/column.rb",
29
- "lib/property/core_ext/time.rb",
30
- "lib/property/db.rb",
31
- "lib/property/declaration.rb",
32
- "lib/property/dirty.rb",
33
- "lib/property/error.rb",
34
- "lib/property/index.rb",
35
- "lib/property/properties.rb",
36
- "lib/property/redefined_method_error.rb",
37
- "lib/property/redefined_property_error.rb",
38
- "lib/property/role.rb",
39
- "lib/property/role_module.rb",
40
- "lib/property/schema.rb",
41
- "lib/property/schema_module.rb",
42
- "lib/property/serialization/json.rb",
43
- "lib/property/serialization/marshal.rb",
44
- "lib/property/serialization/yaml.rb",
45
- "lib/property/stored_column.rb",
46
- "lib/property/stored_role.rb",
47
- "lib/property/stored_schema.rb",
48
- "lib/property/version.rb",
49
- "property.gemspec",
50
- "test/database.rb",
51
- "test/fixtures.rb",
52
- "test/shoulda_macros/index.rb",
53
- "test/shoulda_macros/role.rb",
54
- "test/shoulda_macros/serialization.rb",
55
- "test/test_helper.rb",
56
- "test/unit/property/attribute_test.rb",
57
- "test/unit/property/base_test.rb",
58
- "test/unit/property/column_test.rb",
59
- "test/unit/property/declaration_test.rb",
60
- "test/unit/property/dirty_test.rb",
61
- "test/unit/property/index_complex_test.rb",
62
- "test/unit/property/index_custom_test.rb",
63
- "test/unit/property/index_field_test.rb",
64
- "test/unit/property/index_foreign_test.rb",
65
- "test/unit/property/index_simple_test.rb",
66
- "test/unit/property/role_test.rb",
67
- "test/unit/property/stored_role_test.rb",
68
- "test/unit/property/validation_test.rb",
69
- "test/unit/serialization/json_test.rb",
70
- "test/unit/serialization/marshal_test.rb",
71
- "test/unit/serialization/yaml_test.rb"
19
+ "History.txt",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "generators/property/property_generator.rb",
24
+ "lib/property.rb",
25
+ "lib/property/attribute.rb",
26
+ "lib/property/base.rb",
27
+ "lib/property/column.rb",
28
+ "lib/property/core_ext/time.rb",
29
+ "lib/property/db.rb",
30
+ "lib/property/declaration.rb",
31
+ "lib/property/dirty.rb",
32
+ "lib/property/error.rb",
33
+ "lib/property/index.rb",
34
+ "lib/property/properties.rb",
35
+ "lib/property/redefined_method_error.rb",
36
+ "lib/property/redefined_property_error.rb",
37
+ "lib/property/role.rb",
38
+ "lib/property/role_module.rb",
39
+ "lib/property/schema.rb",
40
+ "lib/property/schema_module.rb",
41
+ "lib/property/serialization/json.rb",
42
+ "lib/property/serialization/marshal.rb",
43
+ "lib/property/serialization/yaml.rb",
44
+ "lib/property/stored_column.rb",
45
+ "lib/property/stored_role.rb",
46
+ "lib/property/stored_schema.rb",
47
+ "lib/property/version.rb",
48
+ "property.gemspec",
49
+ "test/database.rb",
50
+ "test/fixtures.rb",
51
+ "test/shoulda_macros/index.rb",
52
+ "test/shoulda_macros/role.rb",
53
+ "test/shoulda_macros/serialization.rb",
54
+ "test/test_helper.rb",
55
+ "test/unit/property/attribute_test.rb",
56
+ "test/unit/property/base_test.rb",
57
+ "test/unit/property/column_test.rb",
58
+ "test/unit/property/declaration_test.rb",
59
+ "test/unit/property/dirty_test.rb",
60
+ "test/unit/property/index_complex_test.rb",
61
+ "test/unit/property/index_custom_test.rb",
62
+ "test/unit/property/index_field_test.rb",
63
+ "test/unit/property/index_foreign_test.rb",
64
+ "test/unit/property/index_simple_test.rb",
65
+ "test/unit/property/role_test.rb",
66
+ "test/unit/property/stored_role_test.rb",
67
+ "test/unit/property/validation_test.rb",
68
+ "test/unit/serialization/json_test.rb",
69
+ "test/unit/serialization/marshal_test.rb",
70
+ "test/unit/serialization/yaml_test.rb"
72
71
  ]
73
72
  s.homepage = %q{http://zenadmin.org/635}
74
- s.rdoc_options = ["--charset=UTF-8"]
75
73
  s.require_paths = ["lib"]
76
74
  s.rubyforge_project = %q{property}
77
- s.rubygems_version = %q{1.3.7}
75
+ s.rubygems_version = %q{1.6.1}
78
76
  s.summary = %q{model properties wrap into a single database column}
79
77
  s.test_files = [
80
78
  "test/database.rb",
81
- "test/fixtures.rb",
82
- "test/shoulda_macros/index.rb",
83
- "test/shoulda_macros/role.rb",
84
- "test/shoulda_macros/serialization.rb",
85
- "test/test_helper.rb",
86
- "test/unit/property/attribute_test.rb",
87
- "test/unit/property/base_test.rb",
88
- "test/unit/property/column_test.rb",
89
- "test/unit/property/declaration_test.rb",
90
- "test/unit/property/dirty_test.rb",
91
- "test/unit/property/index_complex_test.rb",
92
- "test/unit/property/index_custom_test.rb",
93
- "test/unit/property/index_field_test.rb",
94
- "test/unit/property/index_foreign_test.rb",
95
- "test/unit/property/index_simple_test.rb",
96
- "test/unit/property/role_test.rb",
97
- "test/unit/property/stored_role_test.rb",
98
- "test/unit/property/validation_test.rb",
99
- "test/unit/serialization/json_test.rb",
100
- "test/unit/serialization/marshal_test.rb",
101
- "test/unit/serialization/yaml_test.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"
102
100
  ]
103
101
 
104
102
  if s.respond_to? :specification_version then
105
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
106
103
  s.specification_version = 3
107
104
 
108
105
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/test/test_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'pathname'
2
2
  $LOAD_PATH.unshift((Pathname(__FILE__).dirname + '..' + 'lib').expand_path)
3
3
 
4
4
  require 'rubygems'
5
+ gem 'activerecord', '2.3.11'
5
6
  require 'test/unit'
6
7
  require 'shoulda'
7
8
  require 'active_record'
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: 15
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
- - 1
9
8
  - 2
10
- version: 2.1.2
9
+ - 0
10
+ version: 2.2.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: 2010-12-04 00:00:00 +01:00
19
+ date: 2011-06-06 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -56,7 +56,6 @@ extensions: []
56
56
  extra_rdoc_files:
57
57
  - README.rdoc
58
58
  files:
59
- - .gitignore
60
59
  - History.txt
61
60
  - MIT-LICENSE
62
61
  - README.rdoc
@@ -114,8 +113,8 @@ homepage: http://zenadmin.org/635
114
113
  licenses: []
115
114
 
116
115
  post_install_message:
117
- rdoc_options:
118
- - --charset=UTF-8
116
+ rdoc_options: []
117
+
119
118
  require_paths:
120
119
  - lib
121
120
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -139,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
138
  requirements: []
140
139
 
141
140
  rubyforge_project: property
142
- rubygems_version: 1.3.7
141
+ rubygems_version: 1.6.1
143
142
  signing_key:
144
143
  specification_version: 3
145
144
  summary: model properties wrap into a single database column
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .DS_Store
2
- coverage
3
- *.gem
4
- log/test.log
5
- .project