venture_base 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in venture_base.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Venture Media Labs Inc.
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,31 @@
1
+ # VentureBase
2
+
3
+ Collection of components used by Venture Media's Rails applications.
4
+
5
+ ## Validators
6
+
7
+ ```
8
+ validates :email, email_format: true, presence: true
9
+ ```
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'venture_base'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install venture_base
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ require 'bundler/gem_tasks'
5
+ rescue LoadError
6
+ raise 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'VentureBase'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc_main = 'README.md'
16
+ rdoc.rdoc_files.include('README.md')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
19
+
20
+ require 'rake/testtask'
21
+
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+
29
+ task :default => :test
@@ -0,0 +1,18 @@
1
+ # Validate fields to look like emails
2
+ #
3
+ # Is not an exhaustive check but prevents emails that can cause Postfix to
4
+ # crash. Specifically emails with special characters in the local part.
5
+ #
6
+ # Does not consider a blank string as invalid.
7
+ #
8
+ # Examples
9
+ # validates :email, email_format: true # optional
10
+ # validates :email, email_format: true, presence: true # required
11
+ class EmailFormatValidator < ActiveModel::EachValidator
12
+ EMAIL_REGEX = /^(([^(),:;<>@\[\\\]\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?$/i
13
+
14
+ def validate_each(record, attr_name, value)
15
+ return if value.blank?
16
+ record.errors.add(attr_name, :email_format, options) unless value =~ EMAIL_REGEX
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ email_format: "is invalid"
@@ -0,0 +1,5 @@
1
+ # Required to add gem's app and config/locales path to application's path
2
+ module VentureBase
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ # require 'rails'
2
+
3
+ # module VentureBase
4
+ # class Railtie < ::Rails::Railtie
5
+ # initializer 'venture_base' do |app|
6
+ # # TODO: add initializer code here
7
+ # end
8
+ # end
9
+ # end
@@ -0,0 +1,3 @@
1
+ module VentureBase
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "venture_base/engine"
2
+ require "venture_base/railtie"
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require File.expand_path("../../app/validators/email_format_validator", __FILE__)
3
+
4
+ class User
5
+ include ActiveModel::Validations
6
+ attr_accessor :email
7
+
8
+ validates :email, email_format: true
9
+ end
10
+
11
+ class EmailValidatorTest < ActiveSupport::TestCase
12
+ def assert_valid_email(email)
13
+ u = User.new
14
+ u.email = email
15
+ assert u.valid?, "Email `#{email}` should be valid"
16
+ end
17
+
18
+ def assert_invalid_email(email)
19
+ u = User.new
20
+ u.email = email
21
+ assert !u.valid?, "Email `#{email}` should be invalid"
22
+ end
23
+
24
+ test "invalid email" do
25
+ assert_invalid_email "foo"
26
+ assert_invalid_email "bar@"
27
+ assert_invalid_email " alice@example.com"
28
+ assert_invalid_email "alice@example.com "
29
+ assert_invalid_email "a lice@example.com"
30
+ assert_invalid_email "alice@e xample.com"
31
+ assert_invalid_email "alice@example.c om"
32
+ assert_invalid_email "alice@example.c"
33
+
34
+ # Technically these are valid email addresses but they cause Postfix to crash
35
+ assert_invalid_email "a(lice@example.com"
36
+ assert_invalid_email "a)lice@example.com"
37
+ assert_invalid_email "a,lice@example.com"
38
+ assert_invalid_email "a:lice@example.com"
39
+ assert_invalid_email "a;lice@example.com"
40
+ assert_invalid_email "a<lice@example.com"
41
+ assert_invalid_email "a>lice@example.com"
42
+ assert_invalid_email "a@lice@example.com"
43
+ assert_invalid_email "a[lice@example.com"
44
+ assert_invalid_email "a\\lice@example.com"
45
+ assert_invalid_email "a]lice@example.com"
46
+ end
47
+
48
+ test "valid email" do
49
+ assert_valid_email ""
50
+ assert_valid_email "alice@example.com"
51
+ assert_valid_email "alice@example.com"
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'test/unit'
5
+ require 'rails'
6
+
7
+ class FakeApplication < Rails::Application; end
8
+
9
+ Rails.application = FakeApplication
10
+ Rails.configuration.action_controller = ActiveSupport::OrderedOptions.new
11
+
12
+ require 'venture_base'
13
+
14
+ # Load support files
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'venture_base/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "venture_base"
8
+ spec.version = VentureBase::VERSION
9
+ spec.authors = ["Gerry Shaw"]
10
+ spec.email = ["gshaw@reinvent.com"]
11
+ spec.summary = %q{Useful components for Rails applications}
12
+ spec.homepage = "https://github.com/reinventinc/venture_base"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'rails', '~> 3.2'
21
+
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: venture_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gerry Shaw
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email:
48
+ - gshaw@reinvent.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - app/validators/email_format_validator.rb
59
+ - config/locales/en.yml
60
+ - lib/venture_base.rb
61
+ - lib/venture_base/engine.rb
62
+ - lib/venture_base/railtie.rb
63
+ - lib/venture_base/version.rb
64
+ - test/email_validator_test.rb
65
+ - test/test_helper.rb
66
+ - venture_base.gemspec
67
+ homepage: https://github.com/reinventinc/venture_base
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -742515945066977767
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: -742515945066977767
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.23
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Useful components for Rails applications
98
+ test_files:
99
+ - test/email_validator_test.rb
100
+ - test/test_helper.rb