unidom-common 0.5.1 → 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/app/models/unidom/common/concerns/model_extension.rb +11 -2
- data/lib/unidom/common/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e79e3b7b4db3ac70210a8fb88bac9c58e1668dbd
|
4
|
+
data.tar.gz: 50a2c297eb2998f4957fd322cbcf36a36db348e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bcf09c5fd2a2a21693ee10c85613fd972707e87f5bed752c78fb9975d6dfa3f023559bd984835361bfc97c5c6ff13e1fd3b3562054c63d26eef2b66d89ac9d8
|
7
|
+
data.tar.gz: 6ee6028c6b9898951ff315dfdf09c0d8bbfc8e659dc24b1f0a68ee16559becb1bd6ff3df1538426789e29b75fcc2ffe4700609351a07802b2e953db162d2e674
|
data/README.md
CHANGED
@@ -40,6 +40,10 @@ end
|
|
40
40
|
Project.coded_as('JIRA').valid_at(Time.now).alive(true) # Same as Project.coded_as('JIRA').valid_at.alive
|
41
41
|
team.projects.valid_during('2015-01-01'..'2015-12-31').dead
|
42
42
|
Project.included_by([ id_1, id_2 ]).excluded_by id_3
|
43
|
+
Project.created_after('2015-01-01 00:00:00')
|
44
|
+
Project.created_not_after('2015-01-01 00:00:00')
|
45
|
+
Project.created_before('2015-01-01 00:00:00')
|
46
|
+
Project.created_not_before('2015-01-01 00:00:00')
|
43
47
|
```
|
44
48
|
|
45
49
|
## No-SQL Columns
|
@@ -48,16 +52,19 @@ class Project < ActiveRecord::Base
|
|
48
52
|
|
49
53
|
include Unidom::Common::Concerns::ModelExtension
|
50
54
|
|
55
|
+
notation_column :creator_comment, :last_updater_comment
|
56
|
+
|
51
57
|
validates :creator_comment, allow_blank: true, length: { in: 2..200 }
|
52
58
|
validates :last_updater_comment, allow_blank: true, length: { in: 2..200 }
|
53
59
|
|
54
|
-
notation_column :creator_comment, :last_updater_comment
|
55
|
-
|
56
60
|
end
|
57
61
|
|
58
62
|
project = Project.new
|
59
63
|
project.creator_comment = 'My first project.' # Stored in project.notation['columns']['creator_comment']
|
60
64
|
project.valid? # true
|
65
|
+
|
66
|
+
Project.notation_column_where(:creator_comment, :like, 'first') # Fuzzy search the creator_comment column
|
67
|
+
Project.notation_column_where(:creator_comment, '=', 'My first project.')
|
61
68
|
```
|
62
69
|
|
63
70
|
## ActiveRecord Migration Naming Convention
|
@@ -21,6 +21,11 @@ module Unidom
|
|
21
21
|
scope :alive, ->(living = true) { where defunct: !living }
|
22
22
|
scope :dead, ->(defunct = true) { where defunct: defunct }
|
23
23
|
|
24
|
+
scope :notation_column_where, ->(name, operator, value) do
|
25
|
+
operation = :like==operator ? { operator: 'ILIKE', value: "%#{value}%" } : { operator: operator.to_s, value: value }
|
26
|
+
where "#{table_name}.notation -> 'columns' ->> '#{name}' #{operation[:operator]} :value", value: operation[:value]
|
27
|
+
end
|
28
|
+
|
24
29
|
if columns_hash['ordinal'].present?
|
25
30
|
validates :ordinal, presence: true, numericality: { integer_only: true, greater_than: 0 }
|
26
31
|
scope :ordinal_is, ->(ordinal) { where ordinal: ordinal }
|
@@ -86,8 +91,12 @@ module Unidom
|
|
86
91
|
if name.ends_with? '_at'
|
87
92
|
matched = /\A(.+)_at\z/.match name
|
88
93
|
class_eval do
|
89
|
-
scope :"#{matched[1]}_on",
|
90
|
-
scope :"#{matched[1]}_during",
|
94
|
+
scope :"#{matched[1]}_on", ->(date) { where name => date.beginning_of_day..date.end_of_day }
|
95
|
+
scope :"#{matched[1]}_during", ->(range) { where name => range }
|
96
|
+
scope :"#{matched[1]}_before", ->(time) { where "#{table_name}.#{name} < :time", time: time }
|
97
|
+
scope :"#{matched[1]}_not_after", ->(time) { where "#{table_name}.#{name} <= :time", time: time }
|
98
|
+
scope :"#{matched[1]}_after", ->(time) { where "#{table_name}.#{name} > :time", time: time }
|
99
|
+
scope :"#{matched[1]}_not_before", ->(time) { where "#{table_name}.#{name} >= :time", time: time }
|
91
100
|
end
|
92
101
|
end
|
93
102
|
|
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: '0.6'
|
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-03-
|
11
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|