unidom-common 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/app/assets/javascripts/unidom/common/application.js +1 -1
- data/app/assets/stylesheets/unidom/common/application.css +0 -1
- data/app/models/unidom/common/concerns/model_extension.rb +15 -13
- data/app/views/layouts/unidom/common/application.html.erb +3 -2
- data/lib/unidom/common/version.rb +1 -1
- data/lib/unidom/common.rb +8 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca933265b356b52f2fb29f19d9dcab614f6e8ba3
|
4
|
+
data.tar.gz: 05c043667b4cc91bfb1f2661188d7993cca150cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7610e17aa6f8cf6bffff0e86345e86a4a7b57633f777c06923539f98c0171af8d2adce5b238df8b4c17d7a4787d6fcf6ab521b9a663300e3baa105385a8ec8f
|
7
|
+
data.tar.gz: 94945148b2d89576357fb44ecdaafabff8c9bfcc526bf77c95ccd12e9697ef646eb96557ec575afd529313a262cd6c172c875de7c27efbf6c7013cae8e668c7d
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/unidom-common.svg)](https://badge.fury.io/rb/unidom-common)
|
5
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-common.svg)](https://gemnasium.com/github.com/topbitdu/unidom-common)
|
5
6
|
|
6
7
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Common domain model engine includes the common models.
|
7
8
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。常用领域模型引擎包括一些常用的模型。
|
@@ -76,21 +77,59 @@ Project.notation_column_where(:creator_comment, '=', 'My first project.')
|
|
76
77
|
|
77
78
|
project.enabled = true
|
78
79
|
project.enabled? # true
|
80
|
+
|
81
|
+
Project.notation_boolean_column_where(:enabled, true) # All enabled projects
|
79
82
|
```
|
80
83
|
|
81
84
|
## ActiveRecord Migration Naming Convention
|
82
85
|
### Domain Models (200YMMDDHHMMSS)
|
86
|
+
|
87
|
+
<table class='table table-striped table-hover'>
|
88
|
+
<caption></caption>
|
89
|
+
<thead>
|
90
|
+
<tr>
|
91
|
+
<th>Ruby Gem</th>
|
92
|
+
<th>Migration</th>
|
93
|
+
<th>Model</th>
|
94
|
+
<th>Description</th>
|
95
|
+
</tr>
|
96
|
+
</thead>
|
97
|
+
<tbody>
|
98
|
+
<tr>
|
99
|
+
<td>unidom-common [![Gem Version](https://badge.fury.io/rb/unidom-common.svg)](https://badge.fury.io/rb/unidom-common)</td>
|
100
|
+
<td>200001DDHHMMSS</td>
|
101
|
+
<td>-</td>
|
102
|
+
<td>The Common domain model engine includes the common models. 常用领域模型引擎包括一些常用的模型。</td>
|
103
|
+
</tr>
|
104
|
+
<tr>
|
105
|
+
<td>unidom-visitor [![Gem Version](https://badge.fury.io/rb/unidom-visitor.svg)](https://badge.fury.io/rb/unidom-visitor)</td>
|
106
|
+
<td>200002DDHHMMSS</td>
|
107
|
+
<td>
|
108
|
+
- Identificating
|
109
|
+
- Authenticating
|
110
|
+
- Recognization
|
111
|
+
- User
|
112
|
+
- Guest
|
113
|
+
- Password
|
114
|
+
</td>
|
115
|
+
<td>The Visitor domain model engine includes Identificating, Authenticating, Recognization, Visitor (User & Guest), and Password models. 访问者领域模型引擎包括身份标识、身份鉴别、身份识别、访问者(用户和游客)、密码的模型。</td>
|
116
|
+
</tr>
|
117
|
+
</tbody>
|
118
|
+
</table>
|
119
|
+
|
83
120
|
* unidom-common: 200001DDHHMMSS
|
84
121
|
* unidom-visitor: 200002DDHHMMSS
|
85
122
|
* unidom-category: 200003DDHHMMSS
|
86
123
|
* unidom-authorization: 200004DDHHMMSS
|
87
124
|
* unidom-accounting: 200005DDHHMMSS
|
88
125
|
* unidom-standard: 200006DDHHMMSS
|
126
|
+
|
89
127
|
* unidom-party: 200101DDHHMMSS
|
90
128
|
* unidom-certificate: 200102DDHHMMSS
|
91
129
|
* unidom-contact: 200103DDHHMMSS
|
92
130
|
* unidom-geo: 200104DDHHMMSS
|
93
131
|
* unidom-property: 200105DDHHMMSS
|
132
|
+
|
94
133
|
* unidom-article_number: 200201DDHHMMSS
|
95
134
|
* unidom-product: 200202DDHHMMSS
|
96
135
|
* unidom-price: 200203DDHHMMSS
|
@@ -100,6 +139,8 @@ project.enabled? # true
|
|
100
139
|
* unidom-promotion: 200207DDHHMMSS
|
101
140
|
* unidom-payment: 200208DDHHMMSS
|
102
141
|
|
142
|
+
* unidom-position: 200402DDHHMMSS
|
143
|
+
|
103
144
|
### Country Extensions (200YMM9NNNMMSS)
|
104
145
|
The YMM part should be identical to the relative part of the Domain Models.
|
105
146
|
The NNN is the numeric code of [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1 "codes for the names of countries, dependent territories, and special areas of geographical interest").
|
@@ -15,11 +15,11 @@ module Unidom
|
|
15
15
|
|
16
16
|
scope :transited_to, ->(states) { where state: states }
|
17
17
|
|
18
|
-
scope :valid_at, ->(now
|
18
|
+
scope :valid_at, ->(now: Time.now) { where "? BETWEEN #{includer.table_name}.opened_at AND #{includer.table_name}.closed_at", now }
|
19
19
|
scope :valid_duration, ->(range) { where "(#{includer.table_name}.opened_at BETWEEN ? AND ?) OR (#{includer.table_name}.closed_at <= ? AND #{includer.table_name}.closed_at >= ?)", range.min, range.max, range.max, range.min }
|
20
20
|
|
21
|
-
scope :alive, ->(living
|
22
|
-
scope :dead, ->(defunct
|
21
|
+
scope :alive, ->(living: true) { where defunct: !living }
|
22
|
+
scope :dead, ->(defunct: true) { where defunct: defunct }
|
23
23
|
|
24
24
|
scope :notation_column_where, ->(name, operator, value) do
|
25
25
|
operation = :like==operator ? { operator: 'ILIKE', value: "%#{value}%" } : { operator: operator.to_s, value: value }
|
@@ -30,35 +30,35 @@ module Unidom
|
|
30
30
|
where "(#{table_name}.notation -> 'columns' ->> '#{name}')::boolean = :value", value: (value ? true : false)
|
31
31
|
end
|
32
32
|
|
33
|
-
if columns_hash['ordinal'].present
|
33
|
+
if columns_hash['ordinal'].present?&&:integer==columns_hash['ordinal'].type
|
34
34
|
validates :ordinal, presence: true, numericality: { integer_only: true, greater_than: 0 }
|
35
35
|
scope :ordinal_is, ->(ordinal) { where ordinal: ordinal }
|
36
36
|
end
|
37
37
|
|
38
|
-
if columns_hash['uuid'].present
|
38
|
+
if columns_hash['uuid'].present?&&:uuid==columns_hash['uuid'].type
|
39
39
|
validates :uuid, presence: true, length: { is: 36 }
|
40
40
|
scope :uuid_is, ->(uuid) { where uuid: uuid }
|
41
41
|
end
|
42
42
|
|
43
|
-
if columns_hash['elemental'].present
|
43
|
+
if columns_hash['elemental'].present?&&:boolean==columns_hash['elemental'].type
|
44
44
|
scope :primary, ->(elemental = true) { where elemental: elemental }
|
45
45
|
end
|
46
46
|
|
47
|
-
if columns_hash['grade'].present
|
47
|
+
if columns_hash['grade'].present?&&:integer==columns_hash['grade'].type
|
48
48
|
validates :grade, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
|
49
49
|
scope :grade_is, ->(grade) { where grade: grade }
|
50
50
|
scope :grade_higher_than, ->(grade) { where "grade > :grade", grade: grade }
|
51
51
|
scope :grade_lower_than, ->(grade) { where "grade < :grade", grade: grade }
|
52
52
|
end
|
53
53
|
|
54
|
-
if columns_hash['priority'].present
|
54
|
+
if columns_hash['priority'].present?&&:integer==columns_hash['priority'].type
|
55
55
|
validates :priority, presence: true, numericality: { integer_only: true, greater_than_or_equal_to: 0 }
|
56
56
|
scope :priority_is, ->(priority) { where priority: priority }
|
57
57
|
scope :priority_higher_than, ->(priority) { where "priority > :priority", priority: priority }
|
58
58
|
scope :priority_lower_than, ->(priority) { where "priority < :priority", priority: priority }
|
59
59
|
end
|
60
60
|
|
61
|
-
if columns_hash['slug'].present
|
61
|
+
if columns_hash['slug'].present?&&:string==columns_hash['slug'].type
|
62
62
|
validates :slug, presence: true, length: { in: 1..columns_hash['slug'].limit }, uniqueness: true
|
63
63
|
scope :slug_is, ->(slug) { where slug: slug }
|
64
64
|
before_validation -> {
|
@@ -77,13 +77,15 @@ module Unidom
|
|
77
77
|
|
78
78
|
name = column_name.to_s
|
79
79
|
|
80
|
-
if 'code'==name
|
80
|
+
if ('code'==name||name.ends_with?('_code'))&&:string==columns_hash[name].type
|
81
81
|
class_eval do
|
82
82
|
if columns_hash[name].null
|
83
83
|
validates name.to_sym, allow_blank: true, length: { maximum: columns_hash[name].limit }
|
84
84
|
scope "#{name}_length_is".to_sym, ->(length) { where "LENGTH(#{name}) = :length", length: length }
|
85
|
-
|
85
|
+
elsif columns_hash[name].limit<=4
|
86
86
|
validates name.to_sym, presence: true, length: { is: columns_hash[name].limit }
|
87
|
+
else
|
88
|
+
validates name.to_sym, presence: true, length: { maximum: columns_hash[name].limit }
|
87
89
|
end
|
88
90
|
scope "#{name}d_as".to_sym, ->(code) { where name => code }
|
89
91
|
scope "not_#{name}d_as".to_sym, ->(code) { where.not name => code }
|
@@ -92,7 +94,7 @@ module Unidom
|
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
|
-
if name.ends_with?
|
97
|
+
if name.ends_with?('_at')&&:datetime==columns_hash[name].type
|
96
98
|
matched = /\A(.+)_at\z/.match name
|
97
99
|
class_eval do
|
98
100
|
scope :"#{matched[1]}_on", ->(date) { where name => date.beginning_of_day..date.end_of_day }
|
@@ -104,7 +106,7 @@ module Unidom
|
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
if name.ends_with?
|
109
|
+
if name.ends_with?('_state')&&:string==columns_hash[name].type
|
108
110
|
matched = /\A(.+)_state\z/.match name
|
109
111
|
class_eval do
|
110
112
|
scope :"#{matched[1]}_transited_to", ->(states) { where name => states }
|
@@ -2,13 +2,14 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Common</title>
|
5
|
-
<%= stylesheet_link_tag
|
6
|
-
<%= javascript_include_tag 'unidom/common/application' %>
|
5
|
+
<%= stylesheet_link_tag 'unidom/common/application', media: 'all' %>
|
7
6
|
<%= csrf_meta_tags %>
|
8
7
|
</head>
|
9
8
|
<body>
|
10
9
|
|
11
10
|
<%= yield %>
|
12
11
|
|
12
|
+
<%= javascript_include_tag 'unidom/common/application' %>
|
13
|
+
|
13
14
|
</body>
|
14
15
|
</html>
|
data/lib/unidom/common.rb
CHANGED
@@ -2,7 +2,15 @@ require 'unidom/common/engine'
|
|
2
2
|
|
3
3
|
module Unidom
|
4
4
|
module Common
|
5
|
+
|
5
6
|
NULL_UUID = '00000000-0000-0000-0000-000000000000'.freeze
|
6
7
|
SELF = '~'.freeze
|
8
|
+
|
9
|
+
#OPENED_AT = Time.utc(1970).freeze
|
10
|
+
#CLOSED_AT = Time.utc(3000).freeze
|
11
|
+
|
12
|
+
#FROM_DATE = '1970-01-01'.freeze
|
13
|
+
#THRU_DATE = '3000-01-01'.freeze
|
14
|
+
|
7
15
|
end
|
8
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '11.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '11.0'
|
69
69
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
70
70
|
The Common domain model engine includes the common models. Unidom (统一领域对象模型)是一系列的领域模型引擎。常用领域模型引擎包括一些常用的模型。
|
71
71
|
email:
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.4
|
113
|
+
rubygems_version: 2.6.4
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Unidom Common Domain Model Engine 常用领域模型引擎
|