address_engine 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ Tue, Mar 8, 2011
2
+ - - - - - - - - -
3
+ - Initial Release
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'rake'
5
+ gem 'jeweler'
6
+ gem 'rspec'
7
+ gem 'cucumber'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ cucumber (0.10.0)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (~> 1.1.2)
8
+ gherkin (~> 2.3.2)
9
+ json (~> 1.4.6)
10
+ term-ansicolor (~> 1.0.5)
11
+ diff-lcs (1.1.2)
12
+ gherkin (2.3.3)
13
+ json (~> 1.4.6)
14
+ git (1.2.5)
15
+ jeweler (1.5.2)
16
+ bundler (~> 1.0.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ json (1.4.6)
20
+ rake (0.8.7)
21
+ rspec (2.4.0)
22
+ rspec-core (~> 2.4.0)
23
+ rspec-expectations (~> 2.4.0)
24
+ rspec-mocks (~> 2.4.0)
25
+ rspec-core (2.4.0)
26
+ rspec-expectations (2.4.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.4.0)
29
+ term-ansicolor (1.0.5)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ cucumber
36
+ jeweler
37
+ rake
38
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Paul Campbell
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.md ADDED
@@ -0,0 +1,28 @@
1
+ # Address Engine #
2
+
3
+ An `Address` model for your Rails 3 apps. Fields inspired from Amazon.com:
4
+
5
+ create_table "addresses", :force => true do |t|
6
+ t.string "email"
7
+ t.string "firstname"
8
+ t.string "lastname"
9
+ t.text "address"
10
+ t.string "city"
11
+ t.string "state_province_region"
12
+ t.string "zip_postal_code"
13
+ t.string "country"
14
+ t.string "phone"
15
+ t.datetime "created_at"
16
+ t.datetime "updated_at"
17
+ t.string "middlename"
18
+ end
19
+
20
+ Requires the `carmen` gem (https://rubygems.org/gems/carmen):
21
+
22
+ gem install carmen
23
+
24
+ ## Copyright ##
25
+
26
+ Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
27
+ further details.
28
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "address_engine"
16
+ gem.homepage = "http://github.com/paulca/address_engine"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{For apps that need an address table in a hurry!}
19
+ gem.description = %Q{Inspired by the address fields on amazon.com}
20
+ gem.email = "paul@rslw.com"
21
+ gem.authors = ["Paul Campbell"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'rails', '~>3.0'
25
+ gem.add_runtime_dependency 'activerecord', '~>3.0'
26
+ gem.files = FileList["[A-Za-z]*", "lib/**/*", "app/**/*"]
27
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ require 'cucumber/rake/task'
43
+ Cucumber::Rake::Task.new(:features)
44
+
45
+ task :default => :spec
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "address_engine #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{address_engine}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Campbell"]
12
+ s.date = %q{2011-03-08}
13
+ s.description = %q{Inspired by the address fields on amazon.com}
14
+ s.email = %q{paul@rslw.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "CHANGELOG",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "address_engine.gemspec",
28
+ "app/models/configurable.rb",
29
+ "lib/address_engine.rb",
30
+ "lib/address_engine/engine.rb",
31
+ "lib/generators/address_engine/install_generator.rb",
32
+ "lib/generators/address_engine/templates/configurable.yml",
33
+ "lib/generators/address_engine/templates/migration.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/paulca/address_engine}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.5.0}
39
+ s.summary = %q{For apps that need an address table in a hurry!}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<rake>, [">= 0"])
46
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
49
+ s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
50
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.0"])
51
+ else
52
+ s.add_dependency(%q<rake>, [">= 0"])
53
+ s.add_dependency(%q<jeweler>, [">= 0"])
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ s.add_dependency(%q<cucumber>, [">= 0"])
56
+ s.add_dependency(%q<rails>, ["~> 3.0"])
57
+ s.add_dependency(%q<activerecord>, ["~> 3.0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rake>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, [">= 0"])
63
+ s.add_dependency(%q<cucumber>, [">= 0"])
64
+ s.add_dependency(%q<rails>, ["~> 3.0"])
65
+ s.add_dependency(%q<activerecord>, ["~> 3.0"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,67 @@
1
+ class Address < ActiveRecord::Base
2
+
3
+ validates_presence_of :firstname, :lastname
4
+ validates_presence_of :country
5
+ validates_format_of :phone, :with => /^[0-9\-\+ ]*$/
6
+ validates_format_of :email, :with => /^[^@]*@.*\.[^\.]*$/, :message => 'is invalid. Please enter an address in the format of your@email_address.com'
7
+ validates_presence_of :phone, :message => ' is required.'
8
+
9
+ def country_name
10
+ Carmen::country_name(country)
11
+ end
12
+
13
+ def order
14
+ order_as_shipping.present? ? order_as_shipping : order_as_billing
15
+ end
16
+
17
+ def shipping_rules
18
+ ShippingRule.for_country(country)
19
+ end
20
+
21
+ def filled_in?
22
+ address? && country?
23
+ end
24
+
25
+ def name
26
+ [].tap do |out|
27
+ out << firstname if firstname.present?
28
+ out << lastname if lastname.present?
29
+ end.join(' ')
30
+ end
31
+
32
+ def parts
33
+ [].tap do |out|
34
+ out << name
35
+ if address.present?
36
+ address.split("\n").each do |line|
37
+ out << line
38
+ end
39
+ end
40
+ out << city if city.present?
41
+ out << state_province_region if state_province_region.present?
42
+ out << zip_postal_code if zip_postal_code.present?
43
+ out << country_name if country.present?
44
+ end
45
+ end
46
+
47
+ def readable_parts
48
+ [].tap do |out|
49
+ out << name
50
+
51
+ if address.present?
52
+ address.split("\n").each do |line|
53
+ out << line
54
+ end
55
+ end
56
+
57
+ last_line = []
58
+ last_line << city if city.present?
59
+ last_line << state_province_region if state_province_region.present?
60
+ last_line << zip_postal_code if zip_postal_code.present?
61
+
62
+ out << last_line.join(', ')
63
+ out << country_name if country.present?
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1 @@
1
+ require 'address_engine/engine'
@@ -0,0 +1,4 @@
1
+ module AddressEngine
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+ module AddressEngine
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname)
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'migration.rb', 'db/migrate/create_addresses.rb'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ # This file controls what config variables you want to be able to allow your users
2
+ # to set, as well as those you'll be able to access from within the application.
3
+ #
4
+ # If you want to be able to access a string config[:site_title], for example:
5
+ #
6
+ # site_title:
7
+ # name: Site Title
8
+ # type: string
9
+ # default: My Site
10
+ #
11
+ # 'name' is the name that appears in the edit form
12
+ #
13
+ # 'type' can be 'string' for a text field, 'password' for a password field or 'text' for a text area
14
+ # 'type' defaults to 'string'
15
+ #
16
+ # 'default' is the default value to use if there's no entry in the database. Otherwise, nil will be returned
17
+ #
18
+ # Some Examples:
19
+ #
20
+ # site_title:
21
+ # name: Site Title
22
+ # default: My Site
23
+ # type: string
24
+ #
25
+ # site_description:
26
+ # name: Description for Google
27
+ # default: Lots of Awesomeness Here
28
+ # type: text
29
+ #
30
+ # secret:
31
+ # name: Secret Password for Accessing Secret Areas
32
+ # default: secret
33
+ # type: password
@@ -0,0 +1,22 @@
1
+ class CreateAddresses < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "addresses", :force => true do |t|
4
+ t.string "email"
5
+ t.string "firstname"
6
+ t.string "lastname"
7
+ t.text "address"
8
+ t.string "city"
9
+ t.string "state_province_region"
10
+ t.string "zip_postal_code"
11
+ t.string "country"
12
+ t.string "phone"
13
+ t.datetime "created_at"
14
+ t.datetime "updated_at"
15
+ t.string "middlename"
16
+ end
17
+ end
18
+
19
+ def self.down
20
+ drop_table :addresses
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: address_engine
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Paul Campbell
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-08 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: rake
33
+ version_requirements: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: jeweler
47
+ version_requirements: *id002
48
+ prerelease: false
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: rspec
61
+ version_requirements: *id003
62
+ prerelease: false
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ name: cucumber
75
+ version_requirements: *id004
76
+ prerelease: false
77
+ - !ruby/object:Gem::Dependency
78
+ type: :runtime
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ hash: 7
85
+ segments:
86
+ - 3
87
+ - 0
88
+ version: "3.0"
89
+ name: rails
90
+ version_requirements: *id005
91
+ prerelease: false
92
+ - !ruby/object:Gem::Dependency
93
+ type: :runtime
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ hash: 7
100
+ segments:
101
+ - 3
102
+ - 0
103
+ version: "3.0"
104
+ name: activerecord
105
+ version_requirements: *id006
106
+ prerelease: false
107
+ description: Inspired by the address fields on amazon.com
108
+ email: paul@rslw.com
109
+ executables: []
110
+
111
+ extensions: []
112
+
113
+ extra_rdoc_files:
114
+ - LICENSE.txt
115
+ - README.md
116
+ files:
117
+ - CHANGELOG
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - VERSION
124
+ - address_engine.gemspec
125
+ - app/models/configurable.rb
126
+ - lib/address_engine.rb
127
+ - lib/address_engine/engine.rb
128
+ - lib/generators/address_engine/install_generator.rb
129
+ - lib/generators/address_engine/templates/configurable.yml
130
+ - lib/generators/address_engine/templates/migration.rb
131
+ has_rdoc: true
132
+ homepage: http://github.com/paulca/address_engine
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.5.0
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: For apps that need an address table in a hurry!
165
+ test_files: []
166
+