maskable_attribute 0.0.2 → 0.0.3

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.1)
4
+ maskable_attribute (0.0.2)
5
5
  rails (>= 2.3.10)
6
6
 
7
7
  GEM
@@ -4,14 +4,14 @@ module MaskableAttribute
4
4
 
5
5
  #:bar
6
6
  #:foo => :bar
7
- #:foo => [ :bar, baz, :qux ]
7
+ #:foo => Proc.new { |object| object.size * 3 }
8
8
  #:foo => { :format => :two_digit }
9
9
  #:foo => { :formats => [ :two_digit, :upcase, :downcase ] }
10
10
  #:bar => { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } }
11
11
  #:bar => { :exclusive_formats => { :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } }
12
12
  #:baz => { :default_format => :titleize }
13
- #:bar => [ :quux, { :formats => ... } ]
14
- #:bar => [ Proc.new { |object| object.size * 3 }, { :formats => ... } ]
13
+ #:bar => { :method => :quux, { :formats => ... } }
14
+ #:bar => { :method => Proc.new { |object| object.size * 3 }, :formats => ... }
15
15
  def initialize(masks)
16
16
  @masks = masks.map do |mask|
17
17
  if mask.is_a? Array
@@ -58,7 +58,9 @@ module MaskableAttribute
58
58
  @method = options
59
59
  options = {}
60
60
  else
61
- if options.is_a? Array
61
+ if options.is_a? Hash
62
+ @method = options.delete(:method) || name.to_sym
63
+ elsif options.is_a? Array
62
64
  @method = options.shift
63
65
  options = options.extract_options!
64
66
  else
@@ -1,3 +1,3 @@
1
1
  module MaskableAttribute
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -160,4 +160,18 @@ class MaskableAttributeTest < ActiveSupport::TestCase
160
160
  Hickwell.maskable_attribute :qux
161
161
  end
162
162
  end
163
+
164
+ test "should be able to handle a proc and a format" do
165
+ class Tickwell < Hickwell
166
+ maskable_attribute :bar, { :foo => {
167
+ :method => Proc.new { "2" },
168
+ :default_format => Proc.new { |value| format "%02d", value }
169
+ }
170
+ }
171
+ end
172
+
173
+ @hickwell = Tickwell.create! :bar => "{foo}"
174
+
175
+ assert_equal "02", @hickwell.bar, "Did not retrieve mask having a proc and a format specified"
176
+ end
163
177
  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.2
4
+ version: 0.0.3
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-06-29 00:00:00.000000000Z
12
+ date: 2012-07-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70349364129120 !ruby/object:Gem::Requirement
16
+ requirement: &70272994594940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.3.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70349364129120
24
+ version_requirements: *70272994594940
25
25
  description: A maskable attribute is an attribute that is made up of other attributes
26
26
  (masks), this ordering is set in the masked attribute and preserved across updates.
27
27
  email: