insurance_policy 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/insurance_policy.gemspec +17 -0
- data/lib/insurance_policy.rb +10 -0
- data/lib/insurance_policy/active_record_extensions.rb +45 -0
- data/lib/insurance_policy/policy.rb +30 -0
- data/lib/insurance_policy/version.rb +5 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 C. Jason Harrelson (midas)
|
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,67 @@
|
|
1
|
+
# InsurancePolicy
|
2
|
+
|
3
|
+
ActiveRecord extension for managing an insurance policy's attributes.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'insurance_policy'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install insurance_policy
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Generate a model and call the method.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class CreateApplicants < ActiveRecord::Migration
|
28
|
+
|
29
|
+
def change
|
30
|
+
create_table :people do |t|
|
31
|
+
t.string :insurance_policy_company, :limit => 150
|
32
|
+
t.string :insurance_policy_number, :limit => 20
|
33
|
+
t.date :insurance_policy_expires_on
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class Person < ActiveRecord::Base
|
40
|
+
|
41
|
+
insurance_policy :insurance_policy
|
42
|
+
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
You can now use the insurance policy methods on the Person instances. You will also be able to use
|
47
|
+
the existing attribute methods.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
person = Person.create!( :insurance_policy_company => 'ACME',
|
51
|
+
:insurance_policy_number => '123456789',
|
52
|
+
:insurance_policy_expires_on => Date.parse( '2012-12-31' ) )
|
53
|
+
|
54
|
+
person.insurance_policy.class #=> InsurancePolicy::Policy
|
55
|
+
person.insurance_policy.company #=> ACME
|
56
|
+
person.insurance_policy.number #=> 123456789
|
57
|
+
person.insurance_policy.expires_on #=> Mon, 31 Dec 2012
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/insurance_policy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["C. Jason Harrelson"]
|
6
|
+
gem.email = ["jason@lookforwardenterprises.com"]
|
7
|
+
gem.description = %q{ActiveRecord extension for managing an insurance policy's attributes.}
|
8
|
+
gem.summary = %q{ActiveRecord extension for managing an insurance policy's attributes. using the composed_of pattern.}
|
9
|
+
gem.homepage = "https://github.com/midas/insurance_policy"
|
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 = "insurance_policy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = InsurancePolicy::VERSION
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "insurance_policy/version"
|
2
|
+
|
3
|
+
module InsurancePolicy
|
4
|
+
|
5
|
+
autoload :ActiveRecordExtensions, "insurance_policy/active_record_extensions"
|
6
|
+
autoload :Policy, "insurance_policy/policy"
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveRecord::Base.send( :include, InsurancePolicy::ActiveRecordExtensions ) if defined?( ActiveRecord::Base )
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module InsurancePolicy
|
2
|
+
|
3
|
+
module ActiveRecordExtensions
|
4
|
+
|
5
|
+
def self.included( base )
|
6
|
+
base.extend ActsMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ActsMethods
|
10
|
+
|
11
|
+
def insurance_policy( *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 :insurance_policies, :insurance_policy
|
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 => "InsurancePolicy::Policy",
|
29
|
+
:mapping => [["#{attr}_company", "company"],
|
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 InsurancePolicy
|
2
|
+
|
3
|
+
class Policy
|
4
|
+
|
5
|
+
attr_reader :company, :number, :expires_on
|
6
|
+
|
7
|
+
def initialize( company, number, expires_on=nil )
|
8
|
+
@company = company
|
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
|
+
[company, number].reject( &:blank? ).
|
21
|
+
join( ' Policy No.: ' )
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
description
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: insurance_policy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- C. Jason Harrelson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ActiveRecord extension for managing an insurance policy's attributes.
|
15
|
+
email:
|
16
|
+
- jason@lookforwardenterprises.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- insurance_policy.gemspec
|
27
|
+
- lib/insurance_policy.rb
|
28
|
+
- lib/insurance_policy/active_record_extensions.rb
|
29
|
+
- lib/insurance_policy/policy.rb
|
30
|
+
- lib/insurance_policy/version.rb
|
31
|
+
homepage: https://github.com/midas/insurance_policy
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: ActiveRecord extension for managing an insurance policy's attributes. using
|
55
|
+
the composed_of pattern.
|
56
|
+
test_files: []
|