unidom-common 1.7.2 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/app/models/unidom/common/concerns/model_extension.rb +1 -1
- data/lib/unidom/common/engine_extension.rb +29 -0
- data/lib/unidom/common/version.rb +1 -1
- data/lib/unidom/common.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 160b4063d0e765826d03c06552720324af909359
|
4
|
+
data.tar.gz: f22d9696f68bb1b47da5e12a91115dfb60ab54f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c57580fa426e2980b8ec027bb3970c19023d984dd1cec6cbef4767c7c8a12e4daaa8d56622811be0716e9485bff01612d4aadc3e1b8d4d5f6d55f10a1e4a681
|
7
|
+
data.tar.gz: 0ccfdb1bebf50723b19942db1632970e2c41b3f3ba723d0f9cf1eab9f8fe8af87962f62f056cbe35a8e1d97a296cf6d88df4a118c0eb88de56fe65db316b7255
|
data/README.md
CHANGED
@@ -519,6 +519,19 @@ hex_digested == Unidom::Common::Numeration.hex digested # true
|
|
519
519
|
|
520
520
|
|
521
521
|
|
522
|
+
## Engine Extension concern
|
523
|
+
|
524
|
+
```ruby
|
525
|
+
module EngineName
|
526
|
+
class Engine < ::Rails::Engine
|
527
|
+
include Unidom::Common::EngineExtension
|
528
|
+
enable_initializer enum_enabled: true, migration_enabled: true
|
529
|
+
end
|
530
|
+
end
|
531
|
+
```
|
532
|
+
|
533
|
+
|
534
|
+
|
522
535
|
## ActiveRecord Migration Naming Convention
|
523
536
|
|
524
537
|
### Domain Models (200YMMDDHHMMSS)
|
@@ -16,7 +16,7 @@ module Unidom::Common::Concerns::ModelExtension
|
|
16
16
|
scope :transited_to, ->(states) { where state: states }
|
17
17
|
|
18
18
|
scope :valid_at, ->(now: Time.now) { where "? BETWEEN #{includer.table_name}.opened_at AND #{includer.table_name}.closed_at", now }
|
19
|
-
scope :valid_duration, ->(range)
|
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
21
|
scope :alive, ->(living: true) { where defunct: !living }
|
22
22
|
scope :dead, ->(defunct: true) { where defunct: defunct }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Unidom::Common::EngineExtension
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
#included do |includer|
|
6
|
+
#end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def enable_initializer(enum_enabled: false, migration_enabled: false)
|
11
|
+
|
12
|
+
if enum_enabled
|
13
|
+
require 'unidom/common/yaml_helper'
|
14
|
+
initializer :load_config_initializers do |app|
|
15
|
+
Unidom::Common::YamlHelper.load_enum config: app.config, root: config.root
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if migration_enabled
|
20
|
+
initializer :append_migrations do |app|
|
21
|
+
config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/unidom/common.rb
CHANGED
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: 1.
|
4
|
+
version: '1.8'
|
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-12-
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/unidom/common.rb
|
119
119
|
- lib/unidom/common/data_helper.rb
|
120
120
|
- lib/unidom/common/engine.rb
|
121
|
+
- lib/unidom/common/engine_extension.rb
|
121
122
|
- lib/unidom/common/numeration.rb
|
122
123
|
- lib/unidom/common/version.rb
|
123
124
|
- lib/unidom/common/yaml_helper.rb
|