transformable 0.0.5 → 1.0.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.
Files changed (3) hide show
  1. data/README.md +42 -2
  2. data/lib/transformable/version.rb +1 -1
  3. metadata +2 -2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Transformable
2
2
 
3
- TODO: Write a gem description
3
+ Lets you manipulate data as it's being set on an object without a lot of setter method boilerplate
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,47 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Use the `clean` method on your objects to create a setter method that manipulates inputs:
22
+
23
+ ```ruby
24
+ class User < ActiveRecord::Base
25
+ include Transformable
26
+ clean(:email) {|e| e.downcase}
27
+ end
28
+
29
+ > u = User.new(email: "foo@BAR.com")
30
+ > u.email
31
+ => "foo@bar.com"
32
+ ```
33
+
34
+ By default, nil values won't be passed through to the block. Use the skip_nil option if you want them:
35
+
36
+ ```ruby
37
+ class User < ActiveRecord::Base
38
+ include Transformable
39
+ clean(:email, :skip_nil => false) {|e| e || "example@foobar.com"}
40
+ end
41
+
42
+ > u = User.new(email: "email@email.com")
43
+ > u.email = nil
44
+ > u.email
45
+ => "example@foobar.com"
46
+ ```
47
+
48
+ I use regexes for removing forbidden characters:
49
+
50
+ ```ruby
51
+ class User < ActiveRecord::Base
52
+ include Transformable
53
+ clean(:email) {|e| e.gsub(/\s/, "")} # remove spaces
54
+ end
55
+
56
+ > u = User.new(email: "f o o @ b a r . c o m")
57
+ > u.email
58
+ => "foo@bar.com"
59
+ ```
60
+
61
+ Transformable works on pure ruby objects as well as ActiveRecord objects!
22
62
 
23
63
  ## Contributing
24
64
 
@@ -1,3 +1,3 @@
1
1
  module Transformable
2
- VERSION = "0.0.5"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transformable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Lets you manipulate data as it's being set on an object without a lot
15
15
  of setter method boilerplate