unidom-contact 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +24 -0
- data/app/assets/javascripts/unidom/contact/application.js +13 -0
- data/app/assets/stylesheets/unidom/contact/application.css +15 -0
- data/app/controllers/unidom/contact/application_controller.rb +2 -0
- data/app/helpers/unidom/contact/application_helper.rb +2 -0
- data/app/models/unidom/contact/contact_subscription.rb +17 -0
- data/app/models/unidom/contact/email_address.rb +98 -0
- data/app/views/layouts/unidom/contact/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20010301000000_create_unidom_contact_subscriptions.rb +36 -0
- data/db/migrate/20010302000000_create_unidom_email_addresses.rb +31 -0
- data/lib/tasks/contact_tasks.rake +4 -0
- data/lib/unidom/contact.rb +6 -0
- data/lib/unidom/contact/engine.rb +15 -0
- data/lib/unidom/contact/version.rb +5 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79f378985c985c223387ea66e346c1ad05fa24b1
|
4
|
+
data.tar.gz: 94f7cb4ab404d8993f912f4713643e40e805d0e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c8a6e26f8cd017b39c8f8251aa3cbbaf3dd2fcb2370774744ed03ceb4f38f5f2d3f0caa01534f2637fe4c2cf3ab2f0def51aa1b24ab2932b65d22443f862bd8
|
7
|
+
data.tar.gz: 45e009c202322aacd132d2bf38c049b28d65847e4620f79ae2f00878740bc657370bc765db438fc40f30e933124fd9d71673bd26fb422b104d45a4bf2d161a69
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Topbit Du
|
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,20 @@
|
|
1
|
+
# Unidom Contact
|
2
|
+
|
3
|
+
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Contact domain model engine includes Contact Subscription and Email Address models.
|
4
|
+
Unidom (统一领域对象模型)是一系列的领域模型引擎。联系方式领域模型引擎包括联系方式订阅和电子邮箱地址的模型。
|
5
|
+
|
6
|
+
## Usage in Gemfile:
|
7
|
+
```ruby
|
8
|
+
gem 'unidom-contact'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Run the Database Migration:
|
12
|
+
```shell
|
13
|
+
rake db:migrate
|
14
|
+
```
|
15
|
+
|
16
|
+
## Call the Model:
|
17
|
+
```ruby
|
18
|
+
Unidom::Contact::ContactSubscription.subscribed_by(subscriber).valid_at.alive.first
|
19
|
+
Unidom::Contact::EmailAddress.full_address_is('topbit.du@gmail.com').first
|
20
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Unidom Contact'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Bundler::GemHelper.install_tasks
|
24
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Contact Subscription 是联系方式和参与者之间的关联关系。
|
2
|
+
|
3
|
+
class Unidom::Contact::ContactSubscription < ActiveRecord::Base
|
4
|
+
|
5
|
+
self.table_name = 'unidom_contact_subscriptions'
|
6
|
+
|
7
|
+
validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
|
8
|
+
validates :grade, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
|
9
|
+
validates :priority, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 1000 }
|
10
|
+
|
11
|
+
belongs_to :contact, polymorphic: true
|
12
|
+
belongs_to :subscriber, polymorphic: true
|
13
|
+
|
14
|
+
scope :contact_is, ->(contact) { where contact: contact }
|
15
|
+
scope :subscribed_by, ->(subscriber) { where subscriber: subscriber }
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Email Address 是电子邮箱地址。
|
2
|
+
|
3
|
+
class Unidom::Contact::EmailAddress < ActiveRecord::Base
|
4
|
+
|
5
|
+
self.table_name = 'unidom_email_addresses'
|
6
|
+
|
7
|
+
validates :personalized_name, presence: true, length: { in: 1..self.columns_hash['personalized_name'].limit }
|
8
|
+
validates :full_address, presence: true, length: { in: 4..self.columns_hash['full_address'].limit }, uniqueness: true
|
9
|
+
validates :local_part, presence: true, length: { in: 1..self.columns_hash['local_part'].limit }
|
10
|
+
validates :domain_part, presence: true, length: { in: 2..self.columns_hash['domain_part'].limit }
|
11
|
+
|
12
|
+
has_many :contact_subscriptions, class_name: 'Unidom::Contact::ContactSubscription', as: :contact
|
13
|
+
|
14
|
+
scope :full_address_is, ->(full_address) { where full_address: full_address }
|
15
|
+
scope :local_part_is, ->(local_part) { where local_part: local_part }
|
16
|
+
scope :domain_part_is, ->(domain_part) { where domain_part: domain_part }
|
17
|
+
|
18
|
+
before_validation do
|
19
|
+
self.full_address.strip!
|
20
|
+
self.personalized_name = self.full_address if self.personalized_name.blank?
|
21
|
+
self.full_address.downcase!
|
22
|
+
self.local_part, self.domain_part = self.full_address.split '@', 2
|
23
|
+
end
|
24
|
+
|
25
|
+
# http://blog.csdn.net/wide288/article/details/20782399
|
26
|
+
=begin
|
27
|
+
/**
|
28
|
+
Validate an email address.
|
29
|
+
Provide email address (raw input)
|
30
|
+
Returns true if the email address has the email
|
31
|
+
address format and the domain exists.
|
32
|
+
*/
|
33
|
+
function validEmail($email)
|
34
|
+
{
|
35
|
+
$isValid = true;
|
36
|
+
$atIndex = strrpos($email, "@");
|
37
|
+
if (is_bool($atIndex) && !$atIndex)
|
38
|
+
{
|
39
|
+
$isValid = false;
|
40
|
+
}
|
41
|
+
else
|
42
|
+
{
|
43
|
+
$domain = substr($email, $atIndex+1);
|
44
|
+
$local = substr($email, 0, $atIndex);
|
45
|
+
$localLen = strlen($local);
|
46
|
+
$domainLen = strlen($domain);
|
47
|
+
if ($localLen < 1 || $localLen > 64)
|
48
|
+
{
|
49
|
+
// local part length exceeded
|
50
|
+
$isValid = false;
|
51
|
+
}
|
52
|
+
else if ($domainLen < 1 || $domainLen > 255)
|
53
|
+
{
|
54
|
+
// domain part length exceeded
|
55
|
+
$isValid = false;
|
56
|
+
}
|
57
|
+
else if ($local[0] == '.' || $local[$localLen-1] == '.')
|
58
|
+
{
|
59
|
+
// local part starts or ends with '.'
|
60
|
+
$isValid = false;
|
61
|
+
}
|
62
|
+
else if (preg_match('/\\.\\./', $local))
|
63
|
+
{
|
64
|
+
// local part has two consecutive dots
|
65
|
+
$isValid = false;
|
66
|
+
}
|
67
|
+
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
|
68
|
+
{
|
69
|
+
// character not valid in domain part
|
70
|
+
$isValid = false;
|
71
|
+
}
|
72
|
+
else if (preg_match('/\\.\\./', $domain))
|
73
|
+
{
|
74
|
+
// domain part has two consecutive dots
|
75
|
+
$isValid = false;
|
76
|
+
}
|
77
|
+
else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
|
78
|
+
str_replace("\\\\","",$local)))
|
79
|
+
{
|
80
|
+
// character not valid in local part unless
|
81
|
+
// local part is quoted
|
82
|
+
if (!preg_match('/^"(\\\\"|[^"])+"$/',
|
83
|
+
str_replace("\\\\","",$local)))
|
84
|
+
{
|
85
|
+
$isValid = false;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
|
89
|
+
{
|
90
|
+
// domain not found in DNS
|
91
|
+
$isValid = false;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return $isValid;
|
95
|
+
}
|
96
|
+
=end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Unidom Contact</title>
|
5
|
+
<%= stylesheet_link_tag 'unidom/contact/application', media: 'all' %>
|
6
|
+
<%= javascript_include_tag 'unidom/contact/application' %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class CreateUnidomContactSubscriptions < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
|
5
|
+
create_table :unidom_contact_subscriptions, id: :uuid do |t|
|
6
|
+
|
7
|
+
t.references :contact, type: :uuid, null: false,
|
8
|
+
polymorphic: { null: false, default: '', limit: 200 }
|
9
|
+
t.references :subscriber, type: :uuid, null: false,
|
10
|
+
polymorphic: { null: false, default: '', limit: 200 }
|
11
|
+
|
12
|
+
t.string :name, null: false, default: '', limit: 32
|
13
|
+
t.text :description
|
14
|
+
|
15
|
+
t.boolean :verified, null: false, default: false
|
16
|
+
t.boolean :elemental, null: false, default: false
|
17
|
+
|
18
|
+
t.integer :grade, null: false, default: 0
|
19
|
+
t.integer :priority, null: false, default: 0
|
20
|
+
|
21
|
+
t.column :state, 'char(1)', null: false, default: 'C'
|
22
|
+
t.datetime :opened_at, null: false, default: ::Time.utc(1970)
|
23
|
+
t.datetime :closed_at, null: false, default: ::Time.utc(3000)
|
24
|
+
t.boolean :defunct, null: false, default: false
|
25
|
+
t.jsonb :notation, null: false, default: {}
|
26
|
+
|
27
|
+
t.timestamps null: false
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
add_index :unidom_contact_subscriptions, :contact_id
|
32
|
+
add_index :unidom_contact_subscriptions, :subscriber_id
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class CreateUnidomEmailAddresses < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
|
5
|
+
create_table :unidom_email_addresses, id: :uuid do |t|
|
6
|
+
|
7
|
+
# http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
|
8
|
+
t.string :personalized_name, null: false, default: '', limit: 254
|
9
|
+
t.string :full_address, null: false, default: '', limit: 254
|
10
|
+
t.string :local_part, null: false, default: '', limit: 64
|
11
|
+
t.string :domain_part, null: false, default: '', limit: 255
|
12
|
+
|
13
|
+
t.boolean :verified, null: false, default: false
|
14
|
+
|
15
|
+
t.column :state, 'char(1)', null: false, default: 'C'
|
16
|
+
t.datetime :opened_at, null: false, default: ::Time.utc(1970)
|
17
|
+
t.datetime :closed_at, null: false, default: ::Time.utc(3000)
|
18
|
+
t.boolean :defunct, null: false, default: false
|
19
|
+
t.jsonb :notation, null: false, default: {}
|
20
|
+
|
21
|
+
t.timestamps null: false
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
add_index :unidom_email_addresses, :full_address, unique: true
|
26
|
+
add_index :unidom_email_addresses, :local_part
|
27
|
+
add_index :unidom_email_addresses, :domain_part
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Unidom
|
2
|
+
module Contact
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
|
6
|
+
isolate_namespace Unidom::Contact
|
7
|
+
|
8
|
+
initializer :append_migrations do |app|
|
9
|
+
config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unidom-contact
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Topbit Du
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unidom-common
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
28
|
+
The Contact domain model engine includes Contact Subscription and Email Address
|
29
|
+
models. Unidom (统一领域对象模型)是一系列的领域模型引擎。联系方式领域模型引擎包括联系方式订阅和电子邮箱地址的模型。
|
30
|
+
email:
|
31
|
+
- topbit.du@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/assets/javascripts/unidom/contact/application.js
|
40
|
+
- app/assets/stylesheets/unidom/contact/application.css
|
41
|
+
- app/controllers/unidom/contact/application_controller.rb
|
42
|
+
- app/helpers/unidom/contact/application_helper.rb
|
43
|
+
- app/models/unidom/contact/contact_subscription.rb
|
44
|
+
- app/models/unidom/contact/email_address.rb
|
45
|
+
- app/views/layouts/unidom/contact/application.html.erb
|
46
|
+
- config/routes.rb
|
47
|
+
- db/migrate/20010301000000_create_unidom_contact_subscriptions.rb
|
48
|
+
- db/migrate/20010302000000_create_unidom_email_addresses.rb
|
49
|
+
- lib/tasks/contact_tasks.rake
|
50
|
+
- lib/unidom/contact.rb
|
51
|
+
- lib/unidom/contact/engine.rb
|
52
|
+
- lib/unidom/contact/version.rb
|
53
|
+
homepage: https://github.com/topbitdu/unidom-contact
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.5.1
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: The Contact domain model engine includes Contact Subscription and Email Address
|
77
|
+
models.
|
78
|
+
test_files: []
|