drivers_license 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ gemdev
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p392
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in drivers_license.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jason Harrelson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # DriversLicense
2
+
3
+ A composed_of implementation of a driver's license for use in Rails projects.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'drivers_license'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install drivers_license
19
+
20
+
21
+ ## Usage
22
+
23
+ Assuming a table people has attribute 'drivers_license\_state', 'drivers_license\_number' and
24
+ 'drivers_license_expires_on'.
25
+
26
+ class Person
27
+
28
+ drivers_license :drivers_license
29
+
30
+ end
31
+
32
+ Now you can use #drivers_license:
33
+
34
+ person = Person.new
35
+
36
+ person.drivers_license.class.name # => DriversLicense::License
37
+
38
+ person.drivers_license_state # => 'TX'
39
+ person.drivers_license.state # => 'TX'
40
+
41
+ person.drivers_license_number # => '123456789'
42
+ person.drivers_license.number # => '123456789'
43
+
44
+ person.drivers_license_expires_on # => '2014-01-01'
45
+ person.drivers_license.number # => '2014-01-01'
46
+
47
+ person.drivers_license.to_s # => 'TX123456789'
48
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/drivers_license/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jason Harrelson"]
6
+ gem.email = ["jason@lookforwardenterprises.com"]
7
+ gem.description = %q{Provides driver's license composed_of attributes.}
8
+ gem.summary = %q{An extension that provides driver's license composed_of attributes.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "drivers_license"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DriversLicense::VERSION
17
+ end
@@ -0,0 +1,10 @@
1
+ require "drivers_license/version"
2
+
3
+ module DriversLicense
4
+
5
+ autoload :ActiveRecordExtensions, "drivers_license/active_record_extensions"
6
+ autoload :License, "drivers_license/license"
7
+
8
+ end
9
+
10
+ ActiveRecord::Base.send( :include, DriversLicense::ActiveRecordExtensions ) if defined?( ActiveRecord::Base )
@@ -0,0 +1,57 @@
1
+ module DriversLicense
2
+
3
+ module ActiveRecordExtensions
4
+
5
+ def self.included( base )
6
+ base.extend ActsMethods
7
+ end
8
+
9
+ module ActsMethods
10
+
11
+ def drivers_license( *args )
12
+ unless included_modules.include? InstanceMethods
13
+ self.class_eval { extend ClassMethods }
14
+ include InstanceMethods
15
+ end
16
+
17
+ options = args.extract_options!
18
+ initialize_compositions( args, options )
19
+ end
20
+ alias_method :drivers_licenses, :drivers_license
21
+
22
+ end
23
+
24
+ module ClassMethods
25
+
26
+ def initialize_compositions( attrs, options )
27
+ if options[:single_field]
28
+ attrs.each do |attr|
29
+ composed_of attr,
30
+ :class_name => 'DriversLicense::License',
31
+ :mapping => [["#{attr}_state_and_number", 'state_and_number'],
32
+ ["#{attr}_expires_on", "expires_on"]] #,
33
+ #:converter => :convert,
34
+ #:allow_nil => true
35
+ end
36
+ else
37
+ attrs.each do |attr|
38
+ composed_of attr,
39
+ :class_name => "DriversLicense::License",
40
+ :mapping => [["#{attr}_state", "state"],
41
+ ["#{attr}_number", "number"],
42
+ ["#{attr}_expires_on", "expires_on"]] #,
43
+ #:converter => :convert,
44
+ #:allow_nil => true
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ module InstanceMethods
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,52 @@
1
+ module DriversLicense
2
+
3
+ class License
4
+
5
+ attr_reader :state, :number, :expires_on
6
+
7
+ def initialize( *args )
8
+ if args.size == 2
9
+ state_and_number = args.first
10
+ else
11
+ state_and_number = [args[0],
12
+ args[1]].reject( &:blank? ).
13
+ join( '' )
14
+ end
15
+
16
+ expires_on = args.last
17
+
18
+ unless state_and_number.blank?
19
+ @state = state_and_number[0..1]
20
+ @number = state_and_number[2..state_and_number.size-1]
21
+ end
22
+
23
+ @expires_on = expires_on
24
+
25
+ self.freeze
26
+ end
27
+
28
+ def expired?
29
+ !expires_on.blank? && Time.zone.now >= expires_on
30
+ end
31
+
32
+ def description
33
+ [state, number].reject( &:blank? ).
34
+ join( ' ' )
35
+ end
36
+
37
+ def for_query
38
+ [state, number].reject( &:blank? ).
39
+ join( '' )
40
+ end
41
+
42
+ def to_s( pattern='' )
43
+ if pattern.empty?
44
+ description
45
+ elsif pattern == :query
46
+ for_query
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,5 @@
1
+ module DriversLicense
2
+
3
+ VERSION = "1.0.0"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drivers_license
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Harrelson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provides driver's license composed_of attributes.
15
+ email:
16
+ - jason@lookforwardenterprises.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .ruby-gemset
22
+ - .ruby-version
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - drivers_license.gemspec
28
+ - lib/drivers_license.rb
29
+ - lib/drivers_license/active_record_extensions.rb
30
+ - lib/drivers_license/license.rb
31
+ - lib/drivers_license/version.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: An extension that provides driver's license composed_of attributes.
56
+ test_files: []