unidom-position 1.1 → 1.2

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: afc0bf6e11bdf01c9a08281323e491af07e9be04
4
- data.tar.gz: 3295a37894a71f6a53716851c33c433b83b5225f
3
+ metadata.gz: b99b9647a75604a07d27ba14e061db245dbeb4e9
4
+ data.tar.gz: abac026ed73cd646d380c6e2b92cf14aab54eda6
5
5
  SHA512:
6
- metadata.gz: 082985ba3c2628b465d8193b3afb50173a8708a1baee92ad40d6e6defad5a52751b60cda54b9800e9d80360df1a02a434eb806ae207ed55c23d79ce4fe223f8c
7
- data.tar.gz: 622f6171cd2c65eae430f6d1a6a01070b668d78be9c61735a705743310dffcdc684368fb6035434e0351a8da49a7e23ed7aafa3a3a63d5ab98bb8f82e5b7718e
6
+ metadata.gz: ed6e5b1df0b221d3f20963e04aecada1ed2c795f023107e4adf2ea501f77516e74096a86c7eea9fa00fc4a136352d72228c08267996583262f3aeb0e3ed71860
7
+ data.tar.gz: 63d9dc98150ab98e4401e5c26a56accd0cc4031e593f1b4df13a5932195b345470db54452e64e8e36b992cfc86413bb14d70218ece062ac1f972a00cd61582b4
data/README.md CHANGED
@@ -19,7 +19,7 @@ gem 'unidom-position'
19
19
  ```shell
20
20
  rake db:migrate
21
21
  ```
22
- The migration versions start with 200101.
22
+ The migration versions start with 200402.
23
23
 
24
24
  ## Call the Model
25
25
  ```ruby
@@ -41,3 +41,20 @@ Unidom::Position::PostReportingStructure.report!(superior_post: chief_programmer
41
41
  ```shell
42
42
  bundle exec rake unidom:position:occupation:import file=/data.csv from_date=2009-11-01 thru_date=2015-10-01 scheme_id= scheme_type=
43
43
  ```
44
+
45
+ ## Include the Concerns
46
+ The Post model already includes the following concerns:
47
+ ```ruby
48
+ include Unidom::Position::Concerns::AsInferiorPost
49
+ include Unidom::Position::Concerns::AsSuperiorPost
50
+ ```
51
+
52
+ ### As Inferior Post
53
+ The As Inferior Post concern do the following tasks for the includer automatically:
54
+ 1. Define the has_many :superior_post_reporting_structures macro as: ``has_many :superior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', source: :inferior_post, foreign_key: :inferior_post_id``
55
+ 2. Define the has_many :superior_posts macro as: ``has_many :superior_posts, through: :superior_post_reporting_structures, source: :superior_post``
56
+
57
+ ### As Superior Post
58
+ The As Superior Post concern do the following tasks for the includer automatically:
59
+ 1. Define the has_many :inferior_post_reporting_structures macro as: ``has_many :inferior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', source: :superior_post, foreign_key: :superior_post_id``
60
+ 2. Define the has_many :inferior_posts macro as: ``has_many :inferior_posts, through: :inferior_post_reporting_structures, source: :inferior_post``
@@ -0,0 +1,12 @@
1
+ module Unidom::Position::Concerns::AsInferiorPost
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ self.included do |includer|
6
+
7
+ has_many :superior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', source: :inferior_post, foreign_key: :inferior_post_id
8
+ has_many :superior_posts, through: :superior_post_reporting_structures, source: :superior_post
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ module Unidom::Position::Concerns::AsSuperiorPost
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ self.included do |includer|
6
+
7
+ has_many :inferior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', source: :superior_post, foreign_key: :superior_post_id
8
+ has_many :inferior_posts, through: :inferior_post_reporting_structures, source: :inferior_post
9
+
10
+ end
11
+
12
+ end
@@ -5,16 +5,12 @@ class Unidom::Position::Post < ActiveRecord::Base
5
5
  self.table_name = 'unidom_posts'
6
6
 
7
7
  include Unidom::Common::Concerns::ModelExtension
8
+ include Unidom::Position::Concerns::AsInferiorPost
9
+ include Unidom::Position::Concerns::AsSuperiorPost
8
10
 
9
11
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
10
12
 
11
13
  belongs_to :organization, polymorphic: true
12
14
  belongs_to :position, class_name: 'Unidom::Position::Position'
13
15
 
14
- has_many :inferior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', foreign_key: :superior_post_id, source: :superior_post
15
- has_many :superior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', foreign_key: :inferior_post_id, source: :inferior_post
16
-
17
- has_many :inferior_posts, through: :inferior_post_reporting_structures, source: :inferior_post
18
- has_many :superior_posts, through: :superior_post_reporting_structures, source: :superior_post
19
-
20
16
  end
@@ -12,10 +12,10 @@ class Unidom::Position::PostReportingStructure < ActiveRecord::Base
12
12
  scope :superior_post_is, ->(superior_post) { where superior_post_id: to_id(superior_post) }
13
13
  scope :inferior_post_is, ->(inferior_post) { where inferior_post_id: to_id(inferior_post) }
14
14
 
15
- def self.report!(superior_post: nil, inferior_post: nil, opened_at: Time.now, elemental: true)
15
+ def self.report!(superior_post: nil, inferior_post: nil, elemental: true, opened_at: Time.now)
16
16
  raise ArgumentError.new('The superior_post argument is required.') if superior_post.blank?
17
17
  raise ArgumentError.new('The inferior_post argument is required.') if inferior_post.blank?
18
- self.inferior_post_is(inferior_post).superior_post_is(superior_post).valid_at.alive.first_or_create! opened_at: opened_at, elemental: elemental
18
+ self.inferior_post_is(inferior_post).superior_post_is(superior_post).valid_at.alive.first_or_create! elemental: elemental, opened_at: opened_at
19
19
  end
20
20
 
21
21
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Position
3
- VERSION = '1.1'.freeze
3
+ VERSION = '1.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-position
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
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-06-30 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.9'
27
27
  description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
@@ -40,6 +40,8 @@ files:
40
40
  - app/assets/stylesheets/unidom/position/application.css
41
41
  - app/controllers/unidom/position/application_controller.rb
42
42
  - app/helpers/unidom/position/application_helper.rb
43
+ - app/models/unidom/position/concerns/as_inferior_post.rb
44
+ - app/models/unidom/position/concerns/as_superior_post.rb
43
45
  - app/models/unidom/position/occupation.rb
44
46
  - app/models/unidom/position/position.rb
45
47
  - app/models/unidom/position/post.rb