maskable_attribute 0.0.5 → 0.0.6

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maskable_attribute (0.0.4)
4
+ maskable_attribute (0.0.6)
5
5
  rails (>= 2.3.10)
6
6
 
7
7
  GEM
@@ -13,8 +13,7 @@ module MaskableAttribute
13
13
  #
14
14
  # class Foo < ActiveRecord::Base
15
15
  # maskable_attrribute :some_attribute,
16
- # [ :some_method_be_used_as_a_mask, :another_attribute_mask ],
17
- # :protected_prefixes => [ 'prefix' ]
16
+ # [ :some_method_be_used_as_a_mask, :another_attribute_mask ]
18
17
  # end
19
18
 
20
19
  def maskable_attribute(attribute_to_mask, masks, options = {})
@@ -28,10 +27,12 @@ module MaskableAttribute
28
27
 
29
28
  define_method attribute_to_mask do
30
29
  send("maskable_#{attribute_to_mask}").to_s
30
+ #masked_attribute attribute_to_mask, options
31
31
  end
32
32
 
33
33
  define_method "#{attribute_to_mask}=" do |value|
34
- write_attribute attribute_to_mask, masked_attribute(attribute_to_mask, options).set(value)
34
+ #write_attribute attribute_to_mask, masked_attribute(attribute_to_mask, options).set(value)
35
+ write_attribute attribute_to_mask, value
35
36
  end
36
37
 
37
38
  define_method "maskable_#{attribute_to_mask}" do
@@ -6,7 +6,6 @@ module MaskableAttribute
6
6
  @object = object
7
7
  @attribute = attribute
8
8
  @masks = Masks.new masks
9
- @protected_prefixes = Array.wrap(options.delete(:protected_prefixes) || options.delete(:protected_prefix)).join('|')
10
9
  end
11
10
 
12
11
  def masks
@@ -24,12 +23,14 @@ module MaskableAttribute
24
23
  value
25
24
  end
26
25
 
27
- alias :to_s :masked
28
-
29
- def masked_object
30
- @object
26
+ # update an attribute to replace all masks in place
27
+ # i.e. "something{some_mask}cool" will become "somethingelsecool"
28
+ def demask
29
+ @object.write_attribute attribute, masked
31
30
  end
32
31
 
32
+ alias :to_s :masked
33
+
33
34
  def unmasked
34
35
  @object.read_attribute attribute
35
36
  end
@@ -42,6 +43,7 @@ module MaskableAttribute
42
43
  end
43
44
  end
44
45
  end
46
+
45
47
  value
46
48
  end
47
49
 
@@ -1,3 +1,3 @@
1
1
  module MaskableAttribute
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -5,29 +5,23 @@ class MaskableAttributeTest < ActiveSupport::TestCase
5
5
  assert_kind_of Module, MaskableAttribute
6
6
  end
7
7
 
8
- test "should be able to set an attribute to be maskable" do
8
+ test "should set an attribute to be maskable" do
9
9
  assert_respond_to Hickwell, :maskable_attribute, "Can't mask an attribute"
10
10
  end
11
11
 
12
- test "should be able to get available masks" do
12
+ test "should get available masks" do
13
13
  @hickwell = Hickwell.create!
14
14
 
15
15
  assert_respond_to @hickwell.maskable_qux, :masks, "Couldn't get available masks"
16
16
  end
17
17
 
18
- test "should get available masks" do
18
+ test "should get all available masks" do
19
19
  @hickwell = Hickwell.create!
20
20
 
21
21
  assert_equal [ :foo, :bar, :baz ], @hickwell.maskable_qux.masks, "Masks method did not return list of masks"
22
22
  end
23
23
 
24
- test "should have masked_object available to itself" do
25
- @hickwell = Hickwell.create!
26
-
27
- assert_equal @hickwell, @hickwell.maskable_qux.masked_object, "Couldn't determine the masked object"
28
- end
29
-
30
- test "should be able to set masking of attribute" do
24
+ test "should set masking of attribute" do
31
25
  @hickwell = Hickwell.create!
32
26
 
33
27
  @hickwell.qux = "{foo}{bar}{baz}"
@@ -37,78 +31,84 @@ class MaskableAttributeTest < ActiveSupport::TestCase
37
31
  test "should not overwrite attribute with unmasked attribute" do
38
32
  @hickwell = Hickwell.create! :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
39
33
 
40
- assert_equal "abc", @hickwell.qux
41
34
  assert_equal "abc", @hickwell.qux
42
35
  assert_equal "{foo}{bar}{baz}", @hickwell.read_attribute(:qux), "Overwriting attribute with unmasked value"
43
36
  end
44
37
 
45
- test "should be able to get attribute masked (by default)" do
38
+ test "should get attribute masked by default" do
46
39
  @hickwell = Hickwell.create! :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
47
40
 
48
41
  assert_equal "abc", @hickwell.qux, "Couldn't get attribute masked"
49
42
  end
50
43
 
51
- test "should be able to get attribute unmasked" do
44
+ test "should get attribute unmasked" do
52
45
  @hickwell = Hickwell.create! :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
53
46
 
54
47
  assert_equal "{foo}{bar}{baz}", @hickwell.maskable_qux.unmasked, "Could not get attribute unmasked"
55
48
  end
56
49
 
57
- test "should be able to get set value of attribute and have masks persist" do
50
+ test "should demask attribute to a string" do
58
51
  @hickwell = Hickwell.create! :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
59
- @hickwell.qux = "bac"
52
+ @hickwell.maskable_qux.demask
53
+
54
+ assert_equal "abc", @hickwell.maskable_qux.unmasked, "Did not demask attribute"
55
+ end
56
+
57
+ test "should only save masks when defined explicitly" do
58
+ @hickwell = Hickwell.new :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
59
+ @hickwell.qux = "b{bar}a{baz}"
60
60
 
61
- assert_equal "{bar}{foo}{baz}", @hickwell.maskable_qux.unmasked, "Masks didn't persist though update"
61
+ assert_equal @hickwell.maskable_qux.unmasked, "b{bar}a{baz}", "Incorrectly saved masks for non-specified values"
62
62
  end
63
63
 
64
- test "masks should be able to reference differently named methods" do
64
+ test "should reference differently named methods" do
65
65
  class Rickwell < Hickwell
66
66
  maskable_attribute :bar, :qux => :quux
67
67
  end
68
68
 
69
69
  @hickwell = Rickwell.create! :bar => "{qux}"
70
70
 
71
- assert_equal "thud", @hickwell.bar
71
+ assert_equal "thud", @hickwell.maskable_bar.masked
72
72
  end
73
73
 
74
74
  test "should allow maskable_attribute to be nil" do
75
75
  @hickwell = Hickwell.create! :foo => "a", :bar => "b", :baz => "c", :qux => "{foo}{bar}{baz}"
76
76
  @hickwell.qux = nil
77
77
 
78
- assert_nil @hickwell.qux, "Maskable attribute not set to nil"
78
+ assert_nil @hickwell.maskable_qux.masked, "Maskable attribute not set to nil"
79
79
  end
80
80
 
81
- test "masks should be able to reference a Proc block" do
81
+ test "should reference a Proc block" do
82
82
  class Wickwell < Hickwell
83
83
  maskable_attribute :baz, :ack => Proc.new { "syn" }
84
84
  end
85
85
 
86
86
  @hickwell = Wickwell.create! :baz => "{ack}"
87
87
 
88
- assert_equal "syn", @hickwell.baz
88
+ assert_equal "syn", @hickwell.maskable_baz.masked
89
89
  end
90
90
 
91
- test "masks should be able to handle multiple words" do
91
+ test "should handle multiple words" do
92
92
  class Dickwell < Hickwell
93
93
  maskable_attribute :bar, :foo_bar => Proc.new { "syn" }
94
94
  end
95
95
 
96
96
  @hickwell = Dickwell.create! :bar => "{foo_bar}"
97
97
 
98
- assert_equal "syn", @hickwell.bar, "Did not retrieve mask for multiple words"
98
+ assert_equal "syn", @hickwell.maskable_bar.masked, "Did not retrieve mask for multiple words"
99
99
  end
100
100
 
101
- test "masks should be able to handle multiple words with spaces" do
101
+ test "should handle multiple words with spaces" do
102
102
  class Zickwell < Hickwell
103
103
  maskable_attribute :bar, :foo_bar => Proc.new { "syn" }
104
104
  end
105
105
 
106
106
  @hickwell = Zickwell.create! :bar => "{foo bar}"
107
107
 
108
- assert_equal "syn", @hickwell.bar, "Did not retrieve mask for multiple words with spaces"
108
+ assert_equal "syn", @hickwell.maskable_bar.masked, "Did not retrieve mask for multiple words with spaces"
109
109
  end
110
110
 
111
- test "masks should be able to directly reference methods for the class object" do
111
+ test "should directly reference methods for the class object" do
112
112
  class Fickwell < Hickwell
113
113
  maskable_attribute :bar, [ :foo_bar_baz ]
114
114
 
@@ -118,10 +118,10 @@ class MaskableAttributeTest < ActiveSupport::TestCase
118
118
  end
119
119
  @fickwell = Fickwell.create! :bar => "{foo bar baz}"
120
120
 
121
- assert_equal "ack one", @fickwell.bar, "Did not retrieve mask for object method reference"
121
+ assert_equal "ack one", @fickwell.maskable_bar.masked, "Did not retrieve mask for object method reference"
122
122
  end
123
123
 
124
- test "masks should be able to directly reference aliased methods for the class object" do
124
+ test "should directly reference aliased methods for the class object" do
125
125
  class Fickwell < Hickwell
126
126
  maskable_attribute :bar, [ :fbb ]
127
127
 
@@ -133,10 +133,10 @@ class MaskableAttributeTest < ActiveSupport::TestCase
133
133
  end
134
134
  @hickwell = Fickwell.create! :bar => "{fbb}"
135
135
 
136
- assert_equal "syn two", @hickwell.bar, "Did not retrieve mask for object aliased method reference"
136
+ assert_equal "syn two", @hickwell.maskable_bar.masked, "Did not retrieve mask for object aliased method reference"
137
137
  end
138
138
 
139
- test "should be able to handle masks for non-string types" do
139
+ test "should handle masks for non-string types" do
140
140
  class Nickwell < Hickwell
141
141
  maskable_attribute :baz, [ :number ]
142
142
 
@@ -146,7 +146,7 @@ class MaskableAttributeTest < ActiveSupport::TestCase
146
146
  end
147
147
  @hickwell = Nickwell.create! :baz => "fixture {number}"
148
148
 
149
- assert_equal "fixture 5", @hickwell.baz, "Could not handle non-string type mask"
149
+ assert_equal "fixture 5", @hickwell.maskable_baz.masked, "Could not handle non-string type mask"
150
150
  end
151
151
 
152
152
  test "should raise exception if maskable_attribute isn't actually an attribute" do
@@ -161,7 +161,7 @@ class MaskableAttributeTest < ActiveSupport::TestCase
161
161
  end
162
162
  end
163
163
 
164
- test "should be able to handle a proc and a format" do
164
+ test "should handle a proc and a format" do
165
165
  class Tickwell < Hickwell
166
166
  maskable_attribute :bar, { :foo => {
167
167
  :method => Proc.new { "2" },
@@ -172,10 +172,10 @@ class MaskableAttributeTest < ActiveSupport::TestCase
172
172
 
173
173
  @hickwell = Tickwell.create! :bar => "{foo}"
174
174
 
175
- assert_equal "02", @hickwell.bar, "Did not retrieve mask having a proc and a format specified"
175
+ assert_equal "02", @hickwell.maskable_bar.masked, "Did not retrieve mask having a proc and a format specified"
176
176
  end
177
177
 
178
- test "should not confuse masks' formatting" do
178
+ test "should not confuse mask formatting" do
179
179
  class Pickwell < Hickwell
180
180
  maskable_attribute :bar, { :foo => {
181
181
  :method => Proc.new { "2" },
@@ -186,23 +186,10 @@ class MaskableAttributeTest < ActiveSupport::TestCase
186
186
 
187
187
  @pickwell = Pickwell.create! :bar => "{foo}"
188
188
 
189
- assert_equal "2", @pickwell.bar
190
- @pickwell.bar = "2"
189
+ assert_equal "2", @pickwell.maskable_bar.masked
191
190
  assert_equal "{foo}", @pickwell.maskable_bar.unmasked
192
- @pickwell.bar = "02"
191
+ @pickwell.bar = "{two_digit_foo}"
193
192
  assert_equal "{two_digit_foo}", @pickwell.maskable_bar.unmasked
194
- assert_equal "02", @pickwell.bar
195
- end
196
-
197
- test "should not mask if specified as a non-maskable prefix" do
198
- class Zickwell < Hickwell
199
- maskable_attribute :bar, { :foo => { :method => Proc.new { "TEST" } } }, { :protected_prefixes => [ "prefix" ] }
200
- end
201
-
202
- @zickwell = Zickwell.create! :bar => "TEST"
203
- assert_equal "{foo}", @zickwell.maskable_bar.unmasked, "Mask not being replaced"
204
-
205
- @zickwell.update_attribute :bar, "prefixTEST"
206
- assert_equal "prefixTEST", @zickwell.maskable_bar.unmasked, "Incorrectly masked for non-maskable prefix"
193
+ assert_equal "02", @pickwell.maskable_bar.masked
207
194
  end
208
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maskable_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2012-08-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70148099593740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,12 +21,7 @@ dependencies:
21
21
  version: 2.3.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 2.3.10
24
+ version_requirements: *70148099593740
30
25
  description: A maskable attribute is an attribute that is made up of other attributes
31
26
  (masks), this ordering is set in the masked attribute and preserved across updates.
32
27
  email:
@@ -121,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
116
  version: '0'
122
117
  requirements: []
123
118
  rubyforge_project: maskable_attribute
124
- rubygems_version: 1.8.24
119
+ rubygems_version: 1.8.10
125
120
  signing_key:
126
121
  specification_version: 3
127
122
  summary: Allows Ruby on Rails to have a maskable attribute.