glamorous_validation_jp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
4
+
5
+ # test files
6
+ spec/*.log
7
+ spec/*.sqlite3
8
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in multitenant.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2012 Hirohide Sano
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = Glamorous Validation JP
2
+
3
+ Some useful validators for sexy validation.
4
+
5
+ == Usage
6
+
7
+ == Features
8
+
9
+ * Rails 3 compatible
10
+ * Restrict database queries to only lookup objects for the current tenant
11
+ * Auto assign newly created objects to the current tenant
12
+
13
+ == Contributing
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
+ * Fork the project
18
+ * Start a feature/bugfix branch
19
+ * Commit and push until you are happy with your contribution
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
22
+
23
+ == Credits
24
+
25
+ == Copyright
26
+
27
+ Copyright 2012 Hirohide Sano.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "glamorous_validation_jp/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "glamorous_validation_jp"
7
+ s.version = GlamorousValidationJp::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Hirohide Sano"]
10
+ s.email = ["sanojimaru@gmail.com"]
11
+ s.homepage = "http://github.com/sanojimaru/glamorous_validation_jp"
12
+ s.summary = %q{Some useful validators for sexy validation}
13
+ s.description = %q{Some useful validators for sexy validation.}
14
+
15
+ s.rubyforge_project = "glamorous_validation_jp"
16
+
17
+ s.add_dependency(%q<activemodel>, ['>= 3.1'])
18
+ s.add_development_dependency(%q<rspec>, ['~> 2.6.0'])
19
+ s.add_development_dependency(%q<rspec-core>, ['~> 2.6.4'])
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_model/validations'
2
+ require 'glamorous_validation_jp/email_validator'
3
+
4
+ module GlamorousValidationJp
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'mail'
2
+
3
+ module ActiveModel
4
+ module Validations
5
+ class EmailValidator < ActiveModel::EachValidator
6
+ def initialize(options)
7
+ super(options.reverse_merge(allow_blank: false))
8
+ end
9
+
10
+ def validate_each(record, attr_name, value)
11
+ unless value
12
+ record.errors.add(attr_name, :not_a_email, options) unless options[:allow_blank]
13
+ return
14
+ end
15
+
16
+ record.errors.add(attr_name, :not_a_email, options) unless valid_email(value)
17
+ end
18
+
19
+ private
20
+ def valid_email( value )
21
+ begin
22
+ return false if value == ''
23
+ parsed = Mail::Address.new( value )
24
+ return parsed.address == value && parsed.local != parsed.address
25
+ rescue Mail::Field::ParseError
26
+ return false
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module GlamorousValidationJp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ valid_emails = %w(
4
+ abc@example
5
+ Abc@example.com
6
+ Abc.123@example.com
7
+ user+mailbox/department=shipping@example.com
8
+ !#$%&'*+-/=?^_`.{|}~@example.com
9
+ "Abc@def"@example.com
10
+ "Fred\ Bloggs"@example.com
11
+ "Joe.\\Blow"@example.com
12
+ abc@127.0.0.1
13
+ )
14
+
15
+ invalid_emails = %w(
16
+ Abc.@example.com
17
+ .@example.com
18
+ abc@example,com
19
+ abc@ex:ample.com
20
+ <abc@example.com>
21
+ abc;@exam
22
+ )
23
+
24
+ class Test1 < TestModel
25
+ validates :email, email: true
26
+ end
27
+
28
+ describe ActiveModel::Validations::EmailValidator do
29
+ describe :validation do
30
+ context :valid do
31
+ valid_emails.each do |email|
32
+ it "#{email} should be valid" do
33
+ Test1.new(email: email).should be_valid
34
+ end
35
+ end
36
+ end
37
+
38
+ context :invalid do
39
+ invalid_emails.each do |email|
40
+ it "#{email} no should be valid" do
41
+ Test1.new(email: email).should_not be_valid
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'active_model'
7
+
8
+ require 'glamorous_validation_jp'
9
+
10
+ # Requires supporting files with custom matchers and macros, etc,
11
+ # in ./support/ and its subdirectories.
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+ # Nothing to do
16
+ end
17
+
18
+ class TestModel
19
+ include ActiveModel::Validations
20
+
21
+ def initialize(attributes = {})
22
+ @attributes = attributes
23
+ end
24
+
25
+ def read_attribute_for_validation(key)
26
+ @attributes[key]
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glamorous_validation_jp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hirohide Sano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ requirement: &70278041513220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70278041513220
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70278041512420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70278041512420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-core
38
+ requirement: &70278041511720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70278041511720
47
+ description: Some useful validators for sexy validation.
48
+ email:
49
+ - sanojimaru@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.rdoc
59
+ - Rakefile
60
+ - glamorous_validation_jp.gemspec
61
+ - lib/glamorous_validation_jp.rb
62
+ - lib/glamorous_validation_jp/email_validator.rb
63
+ - lib/glamorous_validation_jp/version.rb
64
+ - spec/glamorous_validation_jp_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: http://github.com/sanojimaru/glamorous_validation_jp
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project: glamorous_validation_jp
86
+ rubygems_version: 1.8.11
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Some useful validators for sexy validation
90
+ test_files:
91
+ - spec/glamorous_validation_jp_spec.rb
92
+ - spec/spec_helper.rb