capsize 0.2.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.mdown +50 -0
- data/capsize.gemspec +25 -0
- data/lib/capsize.rb +26 -0
- data/lib/capsize/version.rb +3 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Readme.mdown
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
What is this nonsense?
|
2
|
+
======================
|
3
|
+
|
4
|
+
Good question. Capsize is an ActiveSupport Concern that came about when replacing archaic software in the car sales industry. Old systems
|
5
|
+
often require that data be entered in ALL CAPS, for readability concerns, random hardware restrictions, or simply out of convention. We needed
|
6
|
+
a quick way to transform existing data to fit a more sane standard, as well as a way to take the data entered by creatures of habit and make
|
7
|
+
it look less like I'm being screamed at.
|
8
|
+
|
9
|
+
How do I get at this goodness?
|
10
|
+
==============================
|
11
|
+
|
12
|
+
It's simple, really.
|
13
|
+
|
14
|
+
w/ Bundler
|
15
|
+
----------
|
16
|
+
|
17
|
+
In your Gemfile:
|
18
|
+
|
19
|
+
gem 'capsize'
|
20
|
+
|
21
|
+
no Bundler
|
22
|
+
----------
|
23
|
+
|
24
|
+
In a terminal somewhere:
|
25
|
+
|
26
|
+
gem install capsize
|
27
|
+
|
28
|
+
How do I use this awesome?
|
29
|
+
==========================
|
30
|
+
|
31
|
+
Also simple. You need to include the module in the models you want this functionality. This was all designed with ActiveRecord in mind, but
|
32
|
+
should work in theory as long as you have getters and setters on your attributes, and ActiveSupport is available, but you haven't tested it,
|
33
|
+
or submitted a patch for your use-case yet, so how should I know?!
|
34
|
+
|
35
|
+
Once you've done that, you just configure the transformations you want on the attributes you want. Pretty easy. Right now only 2 are supported.
|
36
|
+
|
37
|
+
class Person < ActiveRecord::Base
|
38
|
+
include Capsize
|
39
|
+
|
40
|
+
titleize :address, :city
|
41
|
+
downcase :email
|
42
|
+
end
|
43
|
+
|
44
|
+
These examples do exactly what you think, they register a callback on the model that will run the titleize and downcase methods on the named
|
45
|
+
attributes before they are persisted to the database. I really don't know how it could be simpler, but you probably do.
|
46
|
+
|
47
|
+
Who made this crap?
|
48
|
+
===================
|
49
|
+
|
50
|
+
Me. [Corey Woodcox](http://zerp.ly/cwoodcox). I work for [saxton|horne](http://www.saxtonhorne.com) and this was mostly on their time, so I suppose I should mention them.
|
data/capsize.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "capsize/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "capsize"
|
7
|
+
s.version = Capsize::VERSION
|
8
|
+
s.authors = ["Corey Woodcox"]
|
9
|
+
s.email = ["corey.woodcox@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{ActiveModel hooks to apply text transformations to fields on save.}
|
12
|
+
s.description = %q{Don't like CAPSLOCK'd data in your app? Capsize is for you.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "capsize"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "pry"
|
23
|
+
|
24
|
+
s.add_runtime_dependency "activesupport"
|
25
|
+
end
|
data/lib/capsize.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "capsize/version"
|
2
|
+
|
3
|
+
module Capsize
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def downcase(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
capsize!(:downcase, args, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def titleize(*args)
|
13
|
+
options = args.extract_options!
|
14
|
+
capsize!(:titleize, args, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def capsize!(method, attrs, options={})
|
19
|
+
attrs.each do |attribute|
|
20
|
+
set_callback :save, :before, lambda { |record|
|
21
|
+
record.send("#{attribute}=", record.send(attribute).send(method)) if record.send(attribute).present?
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capsize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Corey Woodcox
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: &70237924177860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70237924177860
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70237924177400 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70237924177400
|
36
|
+
description: Don't like CAPSLOCK'd data in your app? Capsize is for you.
|
37
|
+
email:
|
38
|
+
- corey.woodcox@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Rakefile
|
46
|
+
- Readme.mdown
|
47
|
+
- capsize.gemspec
|
48
|
+
- lib/capsize.rb
|
49
|
+
- lib/capsize/version.rb
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project: capsize
|
70
|
+
rubygems_version: 1.8.10
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: ActiveModel hooks to apply text transformations to fields on save.
|
74
|
+
test_files: []
|