Skip to content

Commit

Permalink
address me
Browse files Browse the repository at this point in the history
  • Loading branch information
paulca committed Mar 8, 2011
0 parents commit 001643b
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .document
@@ -0,0 +1,5 @@
lib/**/*.rb
bin/*
-
features/**/*.feature
LICENSE.txt
42 changes: 42 additions & 0 deletions .gitignore
@@ -0,0 +1,42 @@
# rcov generated
coverage

# rdoc generated
rdoc

# yard generated
doc
.yardoc

# bundler
.bundle

# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
# * Run: git config --global core.excludesfile ~/.gitignore
#
# After doing this, these files will be ignored in all your git projects,
# saving you from having to 'pollute' every project you touch with them
#
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
#
# For MacOS:
#
#.DS_Store
#
# For TextMate
#*.tmproj
#tmtags
#
# For emacs:
#*~
#\#*
#.\#*
#
# For vim:
#*.swp
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -0,0 +1,3 @@
Tue, Mar 8, 2011
- - - - - - - - -
- Initial Release
8 changes: 8 additions & 0 deletions Gemfile
@@ -0,0 +1,8 @@
source 'http://rubygems.org'

group :development do
gem 'rake'
gem 'jeweler'
gem 'rspec'
gem 'cucumber'
end
38 changes: 38 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,38 @@
GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
cucumber (0.10.0)
builder (>= 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.3.2)
json (~> 1.4.6)
term-ansicolor (~> 1.0.5)
diff-lcs (1.1.2)
gherkin (2.3.3)
json (~> 1.4.6)
git (1.2.5)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
json (1.4.6)
rake (0.8.7)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
term-ansicolor (1.0.5)

PLATFORMS
ruby

DEPENDENCIES
cucumber
jeweler
rake
rspec
20 changes: 20 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,20 @@
Copyright (c) 2011 Paul Campbell

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 24 additions & 0 deletions README.md
@@ -0,0 +1,24 @@
# Address Engine #

An `Address` model for your Rails 3 apps. Fields inspired from Amazon.com:

create_table "addresses", :force => true do |t|
t.string "email"
t.string "firstname"
t.string "lastname"
t.text "address"
t.string "city"
t.string "state_province_region"
t.string "zip_postal_code"
t.string "country"
t.string "phone"
t.datetime "created_at"
t.datetime "updated_at"
t.string "middlename"
end

## Copyright ##

Copyright (c) 2011 Paul Campbell. See LICENSE.txt for
further details.

56 changes: 56 additions & 0 deletions Rakefile
@@ -0,0 +1,56 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'

require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "address_engine"
gem.homepage = "http://github.com/paulca/address_engine"
gem.license = "MIT"
gem.summary = %Q{For apps that need an address table in a hurry!}
gem.description = %Q{Inspired by the address fields on amazon.com}
gem.email = "paul@rslw.com"
gem.authors = ["Paul Campbell"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
gem.add_runtime_dependency 'rails', '~>3.0'
gem.add_runtime_dependency 'activerecord', '~>3.0'
gem.add_runtime_dependency 'carmen', '~>0.2.6'
gem.files = FileList["[A-Za-z]*", "lib/**/*", "app/**/*"]
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new

require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)

task :default => :spec

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "address_engine #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
1.0.0
67 changes: 67 additions & 0 deletions app/models/configurable.rb
@@ -0,0 +1,67 @@
class Address < ActiveRecord::Base

validates_presence_of :firstname, :lastname
validates_presence_of :country
validates_format_of :phone, :with => /^[0-9\-\+ ]*$/
validates_format_of :email, :with => /^[^@]*@.*\.[^\.]*$/, :message => 'is invalid. Please enter an address in the format of your@email_address.com'
validates_presence_of :phone, :message => ' is required.'

def country_name
Carmen::country_name(country)
end

def order
order_as_shipping.present? ? order_as_shipping : order_as_billing
end

def shipping_rules
ShippingRule.for_country(country)
end

def filled_in?
address? && country?
end

def name
[].tap do |out|
out << firstname if firstname.present?
out << lastname if lastname.present?
end.join(' ')
end

def parts
[].tap do |out|
out << name
if address.present?
address.split("\n").each do |line|
out << line
end
end
out << city if city.present?
out << state_province_region if state_province_region.present?
out << zip_postal_code if zip_postal_code.present?
out << country_name if country.present?
end
end

def readable_parts
[].tap do |out|
out << name

if address.present?
address.split("\n").each do |line|
out << line
end
end

last_line = []
last_line << city if city.present?
last_line << state_province_region if state_province_region.present?
last_line << zip_postal_code if zip_postal_code.present?

out << last_line.join(', ')
out << country_name if country.present?
end
end

end
1 change: 1 addition & 0 deletions lib/address_engine.rb
@@ -0,0 +1 @@
require 'address_engine/engine'
4 changes: 4 additions & 0 deletions lib/address_engine/engine.rb
@@ -0,0 +1,4 @@
module AddressEngine
class Engine < Rails::Engine
end
end
23 changes: 23 additions & 0 deletions lib/generators/address_engine/install_generator.rb
@@ -0,0 +1,23 @@
require 'rails/generators'
module AddressEngine
class InstallGenerator < Rails::Generators::Base
include Rails::Generators::Migration


def self.source_root
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

def self.next_migration_number(dirname)
if ActiveRecord::Base.timestamped_migrations
Time.now.utc.strftime("%Y%m%d%H%M%S")
else
"%.3d" % (current_migration_number(dirname) + 1)
end
end

def create_migration_file
migration_template 'migration.rb', 'db/migrate/create_addresses.rb'
end
end
end
33 changes: 33 additions & 0 deletions lib/generators/address_engine/templates/configurable.yml
@@ -0,0 +1,33 @@
# This file controls what config variables you want to be able to allow your users
# to set, as well as those you'll be able to access from within the application.
#
# If you want to be able to access a string config[:site_title], for example:
#
# site_title:
# name: Site Title
# type: string
# default: My Site
#
# 'name' is the name that appears in the edit form
#
# 'type' can be 'string' for a text field, 'password' for a password field or 'text' for a text area
# 'type' defaults to 'string'
#
# 'default' is the default value to use if there's no entry in the database. Otherwise, nil will be returned
#
# Some Examples:
#
# site_title:
# name: Site Title
# default: My Site
# type: string
#
# site_description:
# name: Description for Google
# default: Lots of Awesomeness Here
# type: text
#
# secret:
# name: Secret Password for Accessing Secret Areas
# default: secret
# type: password
22 changes: 22 additions & 0 deletions lib/generators/address_engine/templates/migration.rb
@@ -0,0 +1,22 @@
class CreateAddresses < ActiveRecord::Migration
def self.up
create_table "addresses", :force => true do |t|
t.string "email"
t.string "firstname"
t.string "lastname"
t.text "address"
t.string "city"
t.string "state_province_region"
t.string "zip_postal_code"
t.string "country"
t.string "phone"
t.datetime "created_at"
t.datetime "updated_at"
t.string "middlename"
end
end

def self.down
drop_table :addresses
end
end

0 comments on commit 001643b

Please sign in to comment.