property_sets 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +3 -3
- data/Appraisals +0 -8
- data/Gemfile +1 -0
- data/Rakefile +2 -0
- data/lib/property_sets/delegator.rb +45 -0
- data/lib/property_sets/version.rb +1 -1
- data/test/helper.rb +7 -1
- data/test/test_delegator.rb +78 -0
- metadata +15 -23
- data/gemfiles/rails3.0.gemfile +0 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e4e1f51f9567dd18fa291875731e3a41c9772461
|
4
|
+
data.tar.gz: e97629c249e9dd6632892f377b55d551587e1dbb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 754e8fe910199e3e80a80bfd138c69b2c1dcc81b744095fd1f091442df5ee186bda98c3c57f8de8a485172e2bc2d8a338509af34662e775f8d4fe8cd6710b5bc
|
7
|
+
data.tar.gz: eb122494452754f9f09b1826fbf653c7eafa730232cda1db6a3462db828d0a0830277396ad38d61e50e5233c37b05f18b6aa5e272f011b38c2b5f0d7bf1b3eee
|
data/.travis.yml
CHANGED
@@ -2,17 +2,17 @@ rvm:
|
|
2
2
|
- ree
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
- 2.1.0
|
5
6
|
- jruby
|
6
7
|
script: "bundle exec rake test"
|
7
8
|
gemfile:
|
8
9
|
- gemfiles/rails2.3.gemfile
|
9
|
-
- gemfiles/rails3.0.gemfile
|
10
10
|
- gemfiles/rails3.2.gemfile
|
11
11
|
matrix:
|
12
12
|
exclude:
|
13
13
|
- rvm: 2.0.0
|
14
14
|
gemfile: gemfiles/rails2.3.gemfile
|
15
|
-
- rvm: 2.
|
16
|
-
gemfile: gemfiles/
|
15
|
+
- rvm: 2.1.0
|
16
|
+
gemfile: gemfiles/rails2.3.gemfile
|
17
17
|
- rvm: ree
|
18
18
|
gemfile: gemfiles/rails3.2.gemfile
|
data/Appraisals
CHANGED
@@ -8,14 +8,6 @@ appraise "rails2.3" do
|
|
8
8
|
gem "test-unit", "< 2.5.5"
|
9
9
|
end
|
10
10
|
|
11
|
-
appraise "rails3.0" do
|
12
|
-
gem "activerecord", "~> 3.0.15"
|
13
|
-
gem "activesupport", "~> 3.0.15"
|
14
|
-
gem "shoulda", "~> 2.11"
|
15
|
-
gem "mysql2", "~> 0.2.0", :platforms => :ruby
|
16
|
-
gem "activerecord-mysql2-adapter", :platforms => :ruby
|
17
|
-
end
|
18
|
-
|
19
11
|
appraise "rails3.2" do
|
20
12
|
gem "activerecord", "~> 3.2.6"
|
21
13
|
gem "activesupport", "~> 3.2.6"
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module PropertySets
|
2
|
+
module Delegator
|
3
|
+
# methods for moving what was once a literal column on
|
4
|
+
# to a property_set table.
|
5
|
+
#
|
6
|
+
# delegates read, write and query methods to the property record or the property default
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# # Migrate :is_open to the :settings property set, and rename it :open,
|
11
|
+
# # and migrate :same to property set :same
|
12
|
+
# include PropertySets::Delegator
|
13
|
+
# delegate_to_property_set :settings, :is_open => :open, :same => :same
|
14
|
+
#
|
15
|
+
def self.included(base)
|
16
|
+
base.extend(ClassMethods)
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def delegate_to_property_set(setname, mappings)
|
21
|
+
raise "Second argument must be a Hash" unless mappings.is_a?(Hash)
|
22
|
+
|
23
|
+
mappings.each do |old_attr, new_attr|
|
24
|
+
define_method(old_attr) { send(setname).send(new_attr) }
|
25
|
+
alias_method "#{old_attr}_before_type_cast", old_attr
|
26
|
+
define_method("#{old_attr}?") { send(setname).send("#{new_attr}?") }
|
27
|
+
define_method("#{old_attr}=") { |value| send(setname).send("#{new_attr}=", value) }
|
28
|
+
|
29
|
+
define_method("#{old_attr}_changed?") do
|
30
|
+
assoc = send(setname)
|
31
|
+
setting = assoc.lookup_without_default(new_attr)
|
32
|
+
|
33
|
+
if !setting
|
34
|
+
false # Nothing has been set which means that the attribute hasn't changed
|
35
|
+
elsif setting.new_record?
|
36
|
+
assoc.default(new_attr) != setting.value
|
37
|
+
else
|
38
|
+
setting.value_changed?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/test/helper.rb
CHANGED
@@ -5,7 +5,7 @@ Bundler.setup
|
|
5
5
|
require 'test/unit'
|
6
6
|
|
7
7
|
begin
|
8
|
-
require 'mocha/setup'
|
8
|
+
require 'mocha/setup' # Rails 2
|
9
9
|
rescue LoadError
|
10
10
|
require 'mocha'
|
11
11
|
end
|
@@ -24,10 +24,13 @@ if ActiveRecord::VERSION::MAJOR > 2 && ActiveRecord::VERSION::MAJOR < 4
|
|
24
24
|
ActiveRecord::Base.attr_accessible
|
25
25
|
end
|
26
26
|
|
27
|
+
I18n.enforce_available_locales = false if ActiveRecord::VERSION::MAJOR > 2
|
28
|
+
|
27
29
|
require File.expand_path "../database", __FILE__
|
28
30
|
|
29
31
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
30
32
|
require 'property_sets'
|
33
|
+
require 'property_sets/delegator'
|
31
34
|
|
32
35
|
class ActiveSupport::TestCase
|
33
36
|
include ActiveRecord::TestFixtures
|
@@ -54,6 +57,9 @@ class ActsLikeAnInteger
|
|
54
57
|
end
|
55
58
|
|
56
59
|
class Account < ActiveRecord::Base
|
60
|
+
include PropertySets::Delegator
|
61
|
+
delegate_to_property_set :settings, :old => :hep
|
62
|
+
|
57
63
|
if ActiveRecord::VERSION::MAJOR < 4
|
58
64
|
attr_accessible :name
|
59
65
|
attr_accessible :texts_attributes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class TestDelegator < ActiveSupport::TestCase
|
4
|
+
context PropertySets::Delegator do
|
5
|
+
fixtures :accounts, :account_settings, :account_texts
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@account = Account.create(:name => "Name")
|
9
|
+
@default = 'skep'
|
10
|
+
end
|
11
|
+
|
12
|
+
context "read" do
|
13
|
+
should "not add a property" do
|
14
|
+
@account.old
|
15
|
+
assert_equal 0, @account.settings.size
|
16
|
+
end
|
17
|
+
|
18
|
+
should "delegate read to default" do
|
19
|
+
assert_equal @default, @account.old
|
20
|
+
end
|
21
|
+
|
22
|
+
should "delegate read to property value" do
|
23
|
+
@account.settings.hep = 'new'
|
24
|
+
assert_equal 'new', @account.old
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "write" do
|
29
|
+
should "add a property" do
|
30
|
+
@account.old = 'new'
|
31
|
+
assert_equal 1, @account.settings.size
|
32
|
+
end
|
33
|
+
|
34
|
+
should "delegate write" do
|
35
|
+
@account.old = 'new'
|
36
|
+
assert_equal 'new', @account.settings.hep
|
37
|
+
assert_equal 'new', @account.old
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "changed?" do
|
42
|
+
should "not add a property" do
|
43
|
+
@account.old_changed?
|
44
|
+
assert_equal 0, @account.settings.size
|
45
|
+
end
|
46
|
+
|
47
|
+
should "not be changed" do
|
48
|
+
assert_equal false, @account.old_changed?
|
49
|
+
end
|
50
|
+
|
51
|
+
should "be changed with new value" do
|
52
|
+
@account.old = "new"
|
53
|
+
assert_equal true, @account.old_changed?
|
54
|
+
end
|
55
|
+
|
56
|
+
should "not be changed with default value" do
|
57
|
+
@account.old = @default
|
58
|
+
assert_equal false, @account.old_changed?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "before_type_case" do
|
63
|
+
should "not add a property" do
|
64
|
+
@account.old_before_type_cast
|
65
|
+
assert_equal 0, @account.settings.size
|
66
|
+
end
|
67
|
+
|
68
|
+
should "return default" do
|
69
|
+
assert_equal @default, @account.old_before_type_cast
|
70
|
+
end
|
71
|
+
|
72
|
+
should "return setting" do
|
73
|
+
@account.old = "new"
|
74
|
+
assert_equal "new", @account.old_before_type_cast
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: property_sets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Morten Primdahl
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.3.14
|
22
20
|
- - <
|
@@ -25,9 +23,8 @@ dependencies:
|
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 2.3.14
|
33
30
|
- - <
|
@@ -36,9 +33,8 @@ dependencies:
|
|
36
33
|
- !ruby/object:Gem::Dependency
|
37
34
|
name: activerecord
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
36
|
requirements:
|
41
|
-
- -
|
37
|
+
- - '>='
|
42
38
|
- !ruby/object:Gem::Version
|
43
39
|
version: 2.3.14
|
44
40
|
- - <
|
@@ -47,9 +43,8 @@ dependencies:
|
|
47
43
|
type: :runtime
|
48
44
|
prerelease: false
|
49
45
|
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
46
|
requirements:
|
52
|
-
- -
|
47
|
+
- - '>='
|
53
48
|
- !ruby/object:Gem::Version
|
54
49
|
version: 2.3.14
|
55
50
|
- - <
|
@@ -58,17 +53,15 @@ dependencies:
|
|
58
53
|
- !ruby/object:Gem::Dependency
|
59
54
|
name: json
|
60
55
|
requirement: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
56
|
requirements:
|
63
|
-
- -
|
57
|
+
- - '>='
|
64
58
|
- !ruby/object:Gem::Version
|
65
59
|
version: '0'
|
66
60
|
type: :runtime
|
67
61
|
prerelease: false
|
68
62
|
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
63
|
requirements:
|
71
|
-
- -
|
64
|
+
- - '>='
|
72
65
|
- !ruby/object:Gem::Version
|
73
66
|
version: '0'
|
74
67
|
description: This gem is an ActiveRecord extension which provides a convenient interface
|
@@ -88,12 +81,12 @@ files:
|
|
88
81
|
- Rakefile
|
89
82
|
- benchmark/read.rb
|
90
83
|
- gemfiles/rails2.3.gemfile
|
91
|
-
- gemfiles/rails3.0.gemfile
|
92
84
|
- gemfiles/rails3.2.gemfile
|
93
85
|
- lib/property_sets.rb
|
94
86
|
- lib/property_sets/action_view_extension.rb
|
95
87
|
- lib/property_sets/active_record_extension.rb
|
96
88
|
- lib/property_sets/casting.rb
|
89
|
+
- lib/property_sets/delegator.rb
|
97
90
|
- lib/property_sets/property_set_model.rb
|
98
91
|
- lib/property_sets/version.rb
|
99
92
|
- property_sets.gemspec
|
@@ -103,32 +96,31 @@ files:
|
|
103
96
|
- test/fixtures/accounts.yml
|
104
97
|
- test/helper.rb
|
105
98
|
- test/test_casting.rb
|
99
|
+
- test/test_delegator.rb
|
106
100
|
- test/test_property_sets.rb
|
107
101
|
- test/test_view_extensions.rb
|
108
102
|
homepage: http://github.com/zendesk/property_sets
|
109
103
|
licenses:
|
110
104
|
- MIT
|
105
|
+
metadata: {}
|
111
106
|
post_install_message:
|
112
107
|
rdoc_options: []
|
113
108
|
require_paths:
|
114
109
|
- lib
|
115
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
111
|
requirements:
|
118
|
-
- -
|
112
|
+
- - '>='
|
119
113
|
- !ruby/object:Gem::Version
|
120
114
|
version: '0'
|
121
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
116
|
requirements:
|
124
|
-
- -
|
117
|
+
- - '>='
|
125
118
|
- !ruby/object:Gem::Version
|
126
119
|
version: '0'
|
127
120
|
requirements: []
|
128
121
|
rubyforge_project:
|
129
|
-
rubygems_version:
|
122
|
+
rubygems_version: 2.0.14
|
130
123
|
signing_key:
|
131
|
-
specification_version:
|
124
|
+
specification_version: 4
|
132
125
|
summary: Property sets for ActiveRecord.
|
133
126
|
test_files: []
|
134
|
-
has_rdoc:
|
data/gemfiles/rails3.0.gemfile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "activerecord-jdbcmysql-adapter", "1.2.2", :platforms=>:jruby
|
6
|
-
gem "rake"
|
7
|
-
gem "bundler"
|
8
|
-
gem "mocha"
|
9
|
-
gem "appraisal"
|
10
|
-
gem "test-unit", ">= 2.5.2"
|
11
|
-
gem "actionpack", ">= 2.3.14", "< 3.3"
|
12
|
-
gem "iconv", :platforms=>:ruby_20
|
13
|
-
gem "activerecord", "~> 3.0.15"
|
14
|
-
gem "activesupport", "~> 3.0.15"
|
15
|
-
gem "shoulda", "~> 2.11"
|
16
|
-
gem "mysql2", "~> 0.2.0", :platforms=>:ruby
|
17
|
-
gem "activerecord-mysql2-adapter", :platforms=>:ruby
|
18
|
-
|
19
|
-
gemspec :path=>"../"
|