license_plate 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 license_plate.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ license_plate (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ license_plate!
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,40 @@
1
+ # LicensePlate
2
+
3
+ A composed_of implementation of a license plate for use in Rails projects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'license_plate'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install license_plate
18
+
19
+ ## Usage
20
+
21
+ Assuming a table people has attribute 'license_plate\_state', 'license_plate_number'.
22
+
23
+ class Person
24
+
25
+ license_plate :license_plate
26
+
27
+ end
28
+
29
+ Now you can use #license_plate:
30
+
31
+ person = Person.new
32
+
33
+ person.license_plate.class.name # => DriversLicense::License
34
+
35
+ person.license_plate_state # => 'TX'
36
+ person.license_plate.state # => 'TX'
37
+
38
+ person.license_plate_number # => 'BZ1234'
39
+ person.license_plate.number # => 'BZ1234'
40
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require "license_plate/version"
2
+
3
+ module LicensePlate
4
+
5
+ autoload :ActiveRecordExtensions, "license_plate/active_record_extensions"
6
+ autoload :Plate, "license_plate/plate"
7
+
8
+ end
9
+
10
+ ActiveRecord::Base.send( :include, LicensePlate::ActiveRecordExtensions ) if defined?( ActiveRecord::Base )
@@ -0,0 +1,45 @@
1
+ module LicensePlate
2
+
3
+ module ActiveRecordExtensions
4
+
5
+ def self.included( base )
6
+ base.extend ActsMethods
7
+ end
8
+
9
+ module ActsMethods
10
+
11
+ def license_plate( *args )
12
+ unless included_modules.include? InstanceMethods
13
+ self.class_eval { extend ClassMethods }
14
+ include InstanceMethods
15
+ end
16
+
17
+ initialize_compositions( args )
18
+ end
19
+ alias_method :license_plates, :license_plate
20
+
21
+ end
22
+
23
+ module ClassMethods
24
+
25
+ def initialize_compositions( attrs )
26
+ attrs.each do |attr|
27
+ composed_of attr,
28
+ :class_name => "LicensePlate::Plate",
29
+ :mapping => [["#{attr}_state", "state"],
30
+ ["#{attr}_number", "number"],
31
+ ["#{attr}_expires_on", "expires_on"]] #,
32
+ #:converter => :convert,
33
+ #:allow_nil => true
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ module InstanceMethods
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,30 @@
1
+ module LicensePlate
2
+
3
+ class Plate
4
+
5
+ attr_reader :state, :number, :expires_on
6
+
7
+ def initialize( state, number, expires_on=nil )
8
+ @state = state
9
+ @number = number
10
+ @expires_on = expires_on
11
+
12
+ self.freeze
13
+ end
14
+
15
+ def expired?
16
+ !expires_on.blank? && Time.zone.now >= expires_on
17
+ end
18
+
19
+ def description
20
+ [state, number].reject( &:blank? ).
21
+ join( ' ' )
22
+ end
23
+
24
+ def to_s
25
+ description
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,5 @@
1
+ module LicensePlate
2
+
3
+ VERSION = "1.0.0"
4
+
5
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/license_plate/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 license plate attributes with composed_of pattern.}
8
+ gem.summary = %q{An extension that provides license plate attributes with composed_of pattern.}
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 = "license_plate"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = LicensePlate::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: license_plate
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 license plate attributes with composed_of pattern.
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
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/license_plate.rb
29
+ - lib/license_plate/active_record_extensions.rb
30
+ - lib/license_plate/plate.rb
31
+ - lib/license_plate/version.rb
32
+ - license_plate.gemspec
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.25
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: An extension that provides license plate attributes with composed_of pattern.
57
+ test_files: []