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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24e769e8684d9d56e76d8d161085488ea1e82a0f
4
- data.tar.gz: 8ad21c94739eed3d56c66ddff5599a71217c920d
3
+ metadata.gz: e79e3b7b4db3ac70210a8fb88bac9c58e1668dbd
4
+ data.tar.gz: 50a2c297eb2998f4957fd322cbcf36a36db348e5
5
5
  SHA512:
6
- metadata.gz: e96569cca721ff84f74a4d7f9ce40d838716dcc653bc1b854f66810a998b7caef409021e07f6dc8244c3a1bb42ec38d25158c785200c0232fb99e1cc984a8412
7
- data.tar.gz: 944f46e8dddb5cb686d2348556129cdca51f9d183fcb8db62b0e1185e9b28261b0c88a67a442560ecf9ab0b517a2f44cc734ec74eb387ac2c62751b29e74d48e
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", ->(date) { where name => date.beginning_of_day..date.end_of_day }
90
- scope :"#{matched[1]}_during", ->(range) { where name => range }
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
 
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Common
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.6'.freeze
4
4
  end
5
5
  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.5.1
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-18 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails