property_sets 2.5.0 → 2.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8b5df00e29ccc0cd797287b319e2590be6da231
4
- data.tar.gz: 7c8d678433474ed11ca89649ed4462636d5cffbb
3
+ metadata.gz: a5d7eb2bd6c0063001b5a2b86995f89107a96da5
4
+ data.tar.gz: a58f90ed7802d717a7c3d1cade7aeb478a69e4c6
5
5
  SHA512:
6
- metadata.gz: 695435a9ae1e80b85144188233235e602eeaec33389167711860fe6fc6903dc65bd76d7e0acb9286df9e1d4a2073ab3ded08779a4912ff1ae803309595597caf
7
- data.tar.gz: 0f26718d6f50123d1516733b5083f028322b12a0ab8fcef60682865b3c336f44187ee3e033d1143d6668a8631b1dadb46fdcbbedb0ae46798629771746f37189
6
+ metadata.gz: 26ffb3ba5727f7b59cb0e4294687d728e4cadd9603c02d3ae94df7a1c3ed1fcbb0acc959fa2b5b613a49cea3d44e470e28a0e09fe970faa7b1c04ec03d1b093b
7
+ data.tar.gz: 1197ac6243e2d2e3f5952af4bf3dc11b8cb56ec89c26fc8cdd848594af29e9950bd58e1fd235d9459f42083d43054d94b2bfe61e499df8a66bed5df9cc44a890
@@ -110,36 +110,18 @@ module PropertySets
110
110
  detect { |property| property.name.to_sym == arg.to_sym }
111
111
  end
112
112
 
113
- if ActiveRecord::VERSION::STRING < "3.2.0"
114
- def lookup_value(type, key)
115
- serialized = property_serialized?(key)
113
+ def lookup_value(type, key)
114
+ serialized = property_serialized?(key)
116
115
 
117
- if instance = lookup_without_default(key)
118
- instance.value_serialized = serialized
119
- PropertySets::Casting.read(type, instance.value)
120
- else
121
- value = default(key)
122
- if serialized
123
- PropertySets::Casting.deserialize(value)
124
- else
125
- PropertySets::Casting.read(type, value)
126
- end
127
- end
128
- end
129
- else
130
- def lookup_value(type, key)
131
- serialized = property_serialized?(key)
132
-
133
- if instance = lookup_without_default(key)
134
- instance.value_serialized = serialized
135
- PropertySets::Casting.read(type, instance.value)
116
+ if instance = lookup_without_default(key)
117
+ instance.value_serialized = serialized
118
+ PropertySets::Casting.read(type, instance.value)
119
+ else
120
+ value = default(key)
121
+ if serialized
122
+ PropertySets::Casting.deserialize(value)
136
123
  else
137
- value = proxy_association.klass.default(key)
138
- if serialized
139
- PropertySets::Casting.deserialize(value)
140
- else
141
- PropertySets::Casting.read(type, value)
142
- end
124
+ PropertySets::Casting.read(type, value)
143
125
  end
144
126
  end
145
127
  end
@@ -150,11 +132,7 @@ module PropertySets
150
132
  instance ||= build_default(arg)
151
133
  instance.value_serialized = property_serialized?(arg)
152
134
 
153
- if ActiveRecord::VERSION::STRING >= "3.1.0"
154
- owner = proxy_association.owner
155
- else
156
- owner = @owner
157
- end
135
+ owner = proxy_association.owner
158
136
 
159
137
  instance.send("#{owner_class_sym}=", owner) if owner.new_record?
160
138
  instance
@@ -2,11 +2,13 @@ require 'json'
2
2
 
3
3
  module PropertySets
4
4
  module Casting
5
+ FALSE = [ "false", "0", "", "off", "n" ]
5
6
 
6
- def self.read(type, value)
7
- return nil if value.nil?
7
+ class << self
8
+ def read(type, value)
9
+ return nil if value.nil?
8
10
 
9
- case type
11
+ case type
10
12
  when :string
11
13
  value
12
14
  when :datetime
@@ -16,17 +18,17 @@ module PropertySets
16
18
  when :integer
17
19
  value.to_i
18
20
  when :boolean
19
- ![ "false", "0", "", "off", "n" ].member?(value.to_s.downcase)
21
+ !false?(value)
20
22
  when :serialized
21
23
  # deserialization happens in the model
22
24
  value
25
+ end
23
26
  end
24
- end
25
27
 
26
- def self.write(type, value)
27
- return nil if value.nil?
28
+ def write(type, value)
29
+ return nil if value.nil?
28
30
 
29
- case type
31
+ case type
30
32
  when :datetime
31
33
  if value.is_a?(String)
32
34
  value
@@ -36,15 +38,23 @@ module PropertySets
36
38
  when :serialized
37
39
  # write the object directly.
38
40
  value
41
+ when :boolean
42
+ false?(value) ? "0" : "1"
39
43
  else
40
44
  value.to_s
45
+ end
41
46
  end
42
- end
43
47
 
44
- def self.deserialize(value)
45
- return nil if value.nil? || value == "null"
46
- JSON.parse(value)
47
- end
48
+ def deserialize(value)
49
+ return nil if value.nil? || value == "null"
50
+ JSON.parse(value)
51
+ end
52
+
53
+ private
48
54
 
55
+ def false?(value)
56
+ FALSE.include?(value.to_s.downcase)
57
+ end
58
+ end
49
59
  end
50
60
  end
@@ -100,21 +100,19 @@ module PropertySets
100
100
  end
101
101
 
102
102
  def default(key)
103
- if @properties[key] && @properties[key].key?(:default)
104
- PropertySets::Casting.read(type(key), @properties[key][:default])
105
- end
103
+ PropertySets::Casting.read(type(key), raw_default(key))
106
104
  end
107
105
 
108
106
  def raw_default(key)
109
- @properties[key] && @properties[key].key?(:default) ? @properties[key][:default] : nil
107
+ @properties[key].try(:[], :default)
110
108
  end
111
109
 
112
110
  def type(key)
113
- @properties[key] && @properties[key].key?(:type) ? @properties[key][:type] : :string
111
+ @properties[key].try(:[], :type) || :string
114
112
  end
115
113
 
116
114
  def protected?(key)
117
- @properties[key] && !!@properties[key][:protected]
115
+ @properties[key].try(:[], :protected) || false
118
116
  end
119
117
 
120
118
  def owner_class=(owner_class_name)
@@ -1,3 +1,3 @@
1
1
  module PropertySets
2
- VERSION = "2.5.0"
2
+ VERSION = "2.6.0"
3
3
  end
metadata CHANGED
@@ -1,67 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property_sets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Primdahl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 2.3.14
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '4.1'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - '>='
28
- - !ruby/object:Gem::Version
29
- version: 2.3.14
30
- - - <
31
- - !ruby/object:Gem::Version
32
- version: '4.1'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: activerecord
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
- - - '>='
17
+ - - ">="
38
18
  - !ruby/object:Gem::Version
39
- version: 2.3.14
40
- - - <
19
+ version: '3.2'
20
+ - - "<"
41
21
  - !ruby/object:Gem::Version
42
22
  version: '4.1'
43
23
  type: :runtime
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
- - - '>='
27
+ - - ">="
48
28
  - !ruby/object:Gem::Version
49
- version: 2.3.14
50
- - - <
29
+ version: '3.2'
30
+ - - "<"
51
31
  - !ruby/object:Gem::Version
52
32
  version: '4.1'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: json
55
35
  requirement: !ruby/object:Gem::Requirement
56
36
  requirements:
57
- - - '>='
37
+ - - ">="
58
38
  - !ruby/object:Gem::Version
59
39
  version: '0'
60
40
  type: :runtime
61
41
  prerelease: false
62
42
  version_requirements: !ruby/object:Gem::Requirement
63
43
  requirements:
64
- - - '>='
44
+ - - ">="
65
45
  - !ruby/object:Gem::Version
66
46
  version: '0'
67
47
  description: This gem is an ActiveRecord extension which provides a convenient interface
@@ -71,18 +51,6 @@ executables: []
71
51
  extensions: []
72
52
  extra_rdoc_files: []
73
53
  files:
74
- - .document
75
- - .gitignore
76
- - .travis.yml
77
- - Appraisals
78
- - Gemfile
79
- - LICENSE
80
- - README.md
81
- - Rakefile
82
- - benchmark/read.rb
83
- - gemfiles/rails2.3.gemfile
84
- - gemfiles/rails3.2.gemfile
85
- - gemfiles/rails4.0.gemfile
86
54
  - lib/property_sets.rb
87
55
  - lib/property_sets/action_view_extension.rb
88
56
  - lib/property_sets/active_record_extension.rb
@@ -90,16 +58,6 @@ files:
90
58
  - lib/property_sets/delegator.rb
91
59
  - lib/property_sets/property_set_model.rb
92
60
  - lib/property_sets/version.rb
93
- - property_sets.gemspec
94
- - test/database.rb
95
- - test/fixtures/account_settings.yml
96
- - test/fixtures/account_texts.yml
97
- - test/fixtures/accounts.yml
98
- - test/helper.rb
99
- - test/test_casting.rb
100
- - test/test_delegator.rb
101
- - test/test_property_sets.rb
102
- - test/test_view_extensions.rb
103
61
  homepage: http://github.com/zendesk/property_sets
104
62
  licenses:
105
63
  - MIT
@@ -110,17 +68,17 @@ require_paths:
110
68
  - lib
111
69
  required_ruby_version: !ruby/object:Gem::Requirement
112
70
  requirements:
113
- - - '>='
71
+ - - ">="
114
72
  - !ruby/object:Gem::Version
115
73
  version: '0'
116
74
  required_rubygems_version: !ruby/object:Gem::Requirement
117
75
  requirements:
118
- - - '>='
76
+ - - ">="
119
77
  - !ruby/object:Gem::Version
120
78
  version: '0'
121
79
  requirements: []
122
80
  rubyforge_project:
123
- rubygems_version: 2.0.14
81
+ rubygems_version: 2.2.2
124
82
  signing_key:
125
83
  specification_version: 4
126
84
  summary: Property sets for ActiveRecord.
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- Gemfile.lock
2
- test/*.log
3
- .rvmrc
4
- coverage
5
- rdoc
6
- doc
7
- .yardoc
8
- .bundle
9
- pkg
10
- gemfiles/*.lock
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- rvm:
2
- - ree
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - jruby
7
- script: "bundle exec rake test"
8
- gemfile:
9
- - gemfiles/rails2.3.gemfile
10
- - gemfiles/rails3.2.gemfile
11
- - gemfiles/rails4.0.gemfile
12
- matrix:
13
- exclude:
14
- - rvm: 2.0.0
15
- gemfile: gemfiles/rails2.3.gemfile
16
- - rvm: 2.1.0
17
- gemfile: gemfiles/rails2.3.gemfile
18
- - rvm: ree
19
- gemfile: gemfiles/rails3.2.gemfile
20
- - rvm: ree
21
- gemfile: gemfiles/rails4.0.gemfile
data/Appraisals DELETED
@@ -1,20 +0,0 @@
1
- appraise "rails2.3" do
2
- gem "activerecord", "~> 2.3.14"
3
- gem "activesupport", "~> 2.3.14"
4
- gem "shoulda", "~> 2.11"
5
- gem "mysql2", "~> 0.2.0", :platforms => :ruby
6
- gem "activerecord-mysql2-adapter", :platforms => :ruby
7
- gem "mocha", "~> 0.12.0"
8
- gem "test-unit", "< 2.5.5"
9
- end
10
-
11
- appraise "rails3.2" do
12
- gem "activerecord", "~> 3.2.6"
13
- gem "activesupport", "~> 3.2.6"
14
- end
15
-
16
- appraise "rails4.0" do
17
- gem "activerecord", "~> 4.0.2"
18
- gem "activesupport", "~> 4.0.2"
19
- gem "protected_attributes"
20
- end
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord-jdbcmysql-adapter', '1.3.5', :platforms => :jruby
4
- gem 'mysql2', :platforms => :ruby
5
-
6
- gem 'bump'
7
- gem 'rake'
8
- gem 'bundler'
9
- gem 'shoulda'
10
- gem 'mocha'
11
- gem 'appraisal'
12
- gem 'test-unit', '>= 2.5.2'
13
- gem 'actionpack', '>= 2.3.14', '< 4.1'
14
- gem 'iconv', :platforms => :ruby_20
15
-
16
- gemspec
data/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS