ssn 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jason Harrelson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,89 @@
1
+ = addressable_record
2
+
3
+ http://github.com/midas/ssn
4
+
5
+
6
+ == DESCRIPTION
7
+
8
+ Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.
9
+
10
+
11
+ == FEATURES
12
+
13
+ * Store a SSN unformatted in a database field with auto formatting when using.
14
+
15
+
16
+ == REQUIREMENTS
17
+
18
+ * active_record >= 2.3
19
+
20
+
21
+ == INSTALL
22
+
23
+ gem sources -a http://gemcutter.org
24
+ sudo gem install ssn
25
+
26
+
27
+ == INSTALL FOR RAILS 3
28
+
29
+ Add to environment file:
30
+
31
+ gem 'ssn', '~>0.1.0'
32
+
33
+ Run:
34
+
35
+ bundle:install
36
+
37
+ == INSTALL FOR RAILS 2
38
+
39
+ Add to environment file:
40
+
41
+ config.gem 'ssn', :version => '~>0.1.0', :source => 'http://gemcutter.org'
42
+
43
+ Run:
44
+
45
+ sudo rake:gems:install
46
+
47
+
48
+ == USAGE
49
+
50
+ Add a raw_ssn that is at least 9 in length to the database table of the model you desire to track a SSN on.
51
+
52
+ Specify usage in your model:
53
+
54
+ class Person
55
+ has_ssn :ssn
56
+ ...
57
+ end
58
+
59
+ Use the field:
60
+
61
+ person = Peson.new :ssn => '123456789'
62
+ person.ssn # => 123-45-6789
63
+ person.ssn = '123-45-6789'
64
+ person.ssn # => 123-45-6789
65
+
66
+
67
+ == Note on Patches/Pull Requests
68
+
69
+ * Fork the project.
70
+ * Make your feature addition or bug fix.
71
+ * Add tests for it. This is important so I don't break it in a
72
+ future version unintentionally.
73
+ * Commit, do not mess with rakefile, version, or history.
74
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
75
+ * Send me a pull request. Bonus points for topic branches.
76
+
77
+
78
+ == Copyright
79
+
80
+ Copyright (c) 2009 C. Jason Harrelson (midas)
81
+
82
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
83
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ssn"
8
+ gem.summary = %Q{Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.}
9
+ gem.description = %Q{Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.}
10
+ gem.email = "jason@lookforwardenterprises.com"
11
+ gem.homepage = "http://github.com/midas/ssn"
12
+ gem.authors = ["Jason Harrelson"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "ssn #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/ssn.rb ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+ require 'ssn/active_record_extensions'
4
+ require 'ssn/social_security_number'
5
+
6
+ module Ssn
7
+ VERSION = '0.1.0'
8
+ end
9
+
10
+ ActiveRecord::Base.send( :include, Ssn::ActiveRecordExtensions ) if defined?( ActiveRecord::Base )
@@ -0,0 +1,56 @@
1
+ module Ssn
2
+ module ActiveRecordExtensions
3
+ def self.included( base )
4
+ base.extend ActsMethods
5
+ end
6
+
7
+ module ActsMethods
8
+ def has_ssn( *args )
9
+ unless included_modules.include? InstanceMethods
10
+ self.class_eval { extend ClassMethods }
11
+ include InstanceMethods
12
+ validates_length_of :raw_ssn, :maximum => 9, :allow_blank => true
13
+ validates_format_of :raw_ssn, :with => /^[0-9]{9}$/, :allow_blank => true
14
+ end
15
+
16
+ initialize_has_ssn_from_args args
17
+ end
18
+
19
+ alias_method :has_ssns, :has_ssn
20
+ end
21
+
22
+ module ClassMethods
23
+ def initialize_has_ssn_from_args( args )
24
+ if args.first.is_a? Symbol
25
+ initialize_has_ssn_from_string args.first.to_s
26
+ elsif args.first.is_a? String
27
+ initialize_has_ssn_from_string args.first
28
+ elsif args.first.is_a? Hash
29
+ initialize_has_ssn_from_hash args.first
30
+ else
31
+ raise 'has_ssn can only accept a string, symbol or hash of strings or symbols'
32
+ end
33
+ end
34
+
35
+ def initialize_has_ssn_from_string( str )
36
+ define_method str do
37
+ return raw_ssn.blank? ? nil : raw_ssn.gsub( /^([0-9]{3})([0-9]{2})([0-9]{4})$/,"\\1-\\2-\\3" )
38
+ end
39
+
40
+ define_method "#{str}=" do |value|
41
+ unless /^[0-9]{3}-?[0-9]{2}-?[0-9]{4}$/.match( value )
42
+ raise 'Invalid SSN format provided for ssn'
43
+ end
44
+ self.raw_ssn = value.gsub( /-/, "" )
45
+ end
46
+ end
47
+
48
+ def initialize_has_ssn_from_hash( args )
49
+ end
50
+ end
51
+
52
+ module InstanceMethods
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module Ssn
2
+ class SocialSecurityNumber
3
+
4
+ end
5
+ end
data/script/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r 'rubygems' -r 'active_record' -r '#{File.dirname(__FILE__) + '/../lib/ssn.rb'}' -r '#{File.dirname(__FILE__) + '/environment'}' -r '#{File.dirname(__FILE__) + '/seed'}'"
9
+
10
+ puts "Loading ssn gem"
11
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,17 @@
1
+ ActiveRecord::Base.configurations = YAML::load( IO.read( File.dirname(__FILE__) + '/../spec/database.yml' ) )
2
+ ActiveRecord::Base.establish_connection( 'test' )
3
+
4
+ ActiveRecord::Schema.define :version => 1 do
5
+ create_table "users", :force => true do |t|
6
+ t.string "name", :limit => 50
7
+ t.string "raw_ssn", :limit => 9
8
+ end
9
+
10
+ create_table "people", :force => true do |t|
11
+ t.string "name", :limit => 50
12
+ end
13
+ end
14
+
15
+ class User < ActiveRecord::Base
16
+ has_ssn :ssn
17
+ end
data/script/seed.rb ADDED
@@ -0,0 +1 @@
1
+ User.create! :name => 'John Smith', :raw_ssn => '123456789'
data/spec/database.yml ADDED
@@ -0,0 +1,3 @@
1
+ test:
2
+ :adapter: sqlite3
3
+ :database: ":memory:"
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'active_record'
5
+ require 'ssn'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
12
+
13
+ require File.dirname(__FILE__) + '/../script/environment'
data/spec/ssn_spec.rb ADDED
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Ssn" do
4
+ describe "having ActiveRecord extensions" do
5
+ it "should respond to has_ssn" do
6
+ ActiveRecord::Base.respond_to?( :has_ssn ).should be_true
7
+ end
8
+
9
+ it "should respond to has_ssns" do
10
+ ActiveRecord::Base.respond_to?( :has_ssns ).should be_true
11
+ end
12
+ end
13
+
14
+ describe "when a user provides a symbol to the has_ssn method" do
15
+ before :each do
16
+ @user = User.new :name => 'John Smith', :raw_ssn => '123456789'
17
+ end
18
+
19
+ it "should respond to a getter method with the correct name" do
20
+ @user.respond_to?( :ssn ).should be_true
21
+ end
22
+
23
+ it "should respond to a setter method with the correct name" do
24
+ @user.respond_to?( :ssn= ).should be_true
25
+ end
26
+
27
+ it "should add a length validation on the raw ssn field" do
28
+ @user.raw_ssn = '1234567890'
29
+ @user.save.should be_false
30
+ end
31
+
32
+ it "should not allow any formatting in the raw ssn field" do
33
+ @user.raw_ssn = '1-3456789'
34
+ @user.save.should be_false
35
+ end
36
+
37
+ it "should not allow a mal-formed social security number" do
38
+ lambda { @user.ssn = "1-1345-6789" }.should raise_error
39
+ end
40
+
41
+ it "should allow correctly formed social security numbers" do
42
+ lambda { @user.ssn = "123-45-6789" }.should_not raise_error
43
+ end
44
+
45
+ it "should allow correctly formed social security numbers" do
46
+ lambda { @user.ssn = "123456789" }.should_not raise_error
47
+ end
48
+ end
49
+
50
+ describe "in general" do
51
+ before :each do
52
+ @user = User.new :name => 'John Smith', :raw_ssn => '123456789'
53
+ end
54
+
55
+ it "should return nil if the raw ssn is nil" do
56
+ @user.raw_ssn = nil
57
+ @user.save!
58
+ @user.ssn.should be_nil
59
+ end
60
+
61
+ it "should return nil if the raw ssn is ''" do
62
+ @user.raw_ssn = ''
63
+ @user.save!
64
+ @user.ssn.should be_nil
65
+ end
66
+
67
+ it "should return a formatted social security number" do
68
+ @user.ssn.should == '123-45-6789'
69
+ end
70
+
71
+ it "should set ssn" do
72
+ @user.ssn = '234-56-7890'
73
+ @user.ssn.should == '234-56-7890'
74
+ end
75
+
76
+ it "should strip formatting from a social security number" do
77
+ @user.ssn = '234-56-7890'
78
+ @user.raw_ssn.should == '234567890'
79
+ end
80
+ end
81
+ end
data/ssn.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ssn}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Harrelson"]
12
+ s.date = %q{2010-10-05}
13
+ s.description = %q{Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.}
14
+ s.email = %q{jason@lookforwardenterprises.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/ssn.rb",
27
+ "lib/ssn/active_record_extensions.rb",
28
+ "lib/ssn/social_security_number.rb",
29
+ "script/console",
30
+ "script/environment.rb",
31
+ "script/seed.rb",
32
+ "spec/database.yml",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb",
35
+ "spec/ssn_spec.rb",
36
+ "ssn.gemspec"
37
+ ]
38
+ s.homepage = %q{http://github.com/midas/ssn}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.}
43
+ s.test_files = [
44
+ "spec/spec_helper.rb",
45
+ "spec/ssn_spec.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
59
+ end
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssn
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jason Harrelson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-05 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.
38
+ email: jason@lookforwardenterprises.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/ssn.rb
54
+ - lib/ssn/active_record_extensions.rb
55
+ - lib/ssn/social_security_number.rb
56
+ - script/console
57
+ - script/environment.rb
58
+ - script/seed.rb
59
+ - spec/database.yml
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ - spec/ssn_spec.rb
63
+ - ssn.gemspec
64
+ has_rdoc: true
65
+ homepage: http://github.com/midas/ssn
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Encapsulates functionality for storing an unformatted SSN but formatting the SSN on print.
98
+ test_files:
99
+ - spec/spec_helper.rb
100
+ - spec/ssn_spec.rb