unidom-score 0.1 → 0.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: 972f92ff143ebea1a4954fece45cf4d42bf9e3c9
4
- data.tar.gz: 080af716b002e1afe55cc01bed48925efee3a60e
3
+ metadata.gz: 1cfeebbf96334fb6987b64e4e7e3f0381ebf88b4
4
+ data.tar.gz: 19b1d37f28aef129b3a1f417a218b018be2a53dd
5
5
  SHA512:
6
- metadata.gz: 363ba44c00d2c77bea115eb8d37357372e3b966865b53039db72a060c3253bf4b9ca5fcc51c16ce166d96c21219a6b435298f7e3363638999e2ee37dcb034ec4
7
- data.tar.gz: dc0c583951803fcbf42e1f7e3f3591f0eed08a177738bf25f8de78f711c4ee6ddccb08e7f125ee690909e77946ed41a10597ecdc6bf4a5e24bb8a2fa7f9dfc90
6
+ metadata.gz: bc1eb6fbf42fba9c165a2d5016f6263bc1e19419599b56160856930776053290c7977038f52a5cf22e14fc91cfa25de3b0bebc961f28d43528d047511c43d022
7
+ data.tar.gz: f84108fd3345b3ca4801ac0a00550dd8eda61cb01641b09f478f5c6bea2670decd053d43855dc8920ed6c56fb91e6c6a7d37c2a4f774318bee22fb5d2a2f0df7
data/README.md CHANGED
@@ -36,5 +36,7 @@ The migration versions start with 200601.
36
36
  ## Call the Model
37
37
 
38
38
  ```ruby
39
- score_sheet = Unidom::Score::ScoreSheet.valid_at.alive.first
39
+ scorer = Unidom::Party::Person.create! name: 'Tim'
40
+ score_keeper = Unidom::Party::Shop.create! name: 'WalMart'
41
+ score_sheet = Unidom::Score::ScoreSheet.score! scorer: scorer, score_keeper: score_keeper, template: nil, name: nil, score: 98, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil
40
42
  ```
@@ -0,0 +1,27 @@
1
+ # Score Item 是评分项。
2
+ # #template 是评分项模版。
3
+ # #scorer 是评分者。
4
+ # #score_keeper 是得分者。
5
+
6
+ class Unidom::Score::ScoreItem < Unidom::Score::ApplicationRecord
7
+
8
+ self.table_name = 'unidom_score_items'
9
+
10
+ include Unidom::Common::Concerns::ModelExtension
11
+
12
+ validates :title, allow_blank: true, length: { in: 2..columns_hash['title'].limit }
13
+ validates :score, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
14
+
15
+ belongs_to :sheet, class_name: 'Unidom::Score::ScoreSheet', foreign_key: :score_sheet_id
16
+ belongs_to :template, class_name: 'Unidom::Score::ScoreItemTemplate', foreign_key: :score_item_template_id
17
+ belongs_to :scorer, polymorphic: true
18
+
19
+ scope :sheet_is, ->(sheet) { where sheet: sheet }
20
+ scope :template_is, ->(template) { where template_id: to_id(template) }
21
+ scope :scored_by, ->(scorer) { where scorer: scorer }
22
+
23
+ def self.score!(sheet: nil, scorer: nil, template: nil, name: template.try(:name), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
24
+ create! sheet: sheet, scorer: scorer, template: template, name: name, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
25
+ end
26
+
27
+ end
@@ -1,5 +1,5 @@
1
1
  # Score Sheet 是评分表。
2
- # #score_sheet_template 是评分表模版。
2
+ # #template 是评分表模版。
3
3
  # #scorer 是评分者。
4
4
  # #score_keeper 是得分者。
5
5
 
@@ -16,6 +16,12 @@ class Unidom::Score::ScoreSheet < Unidom::Score::ApplicationRecord
16
16
  belongs_to :scorer, polymorphic: true
17
17
  belongs_to :score_keeper, polymorphic: true
18
18
 
19
+ has_many :score_items, class_name: 'Unidom::Score::ScoreItem'
20
+
21
+ scope :template_is, ->(template) { where template_id: to_id(template) }
22
+ scope :scored_by, ->(scorer) { where scorer: scorer }
23
+ scope :score_kept_by, ->(score_keeper) { where score_keeper: score_keeper }
24
+
19
25
  def self.score!(scorer: nil, score_keeper: nil, template: nil, name: template.try(:name), score: 0, scored_on: Date.current, opened_at: Time.now, description: nil, instruction: nil)
20
26
  create! scorer: scorer, score_keeper: score_keeper, template: template, name: name, score: score, scored_on: scored_on, opened_at: opened_at, description: description, instruction: instruction
21
27
  end
@@ -0,0 +1,35 @@
1
+ class CreateUnidomScoreItems < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_score_items, id: :uuid do |t|
6
+
7
+ t.references :score_sheet, type: :uuid, null: false
8
+ t.references :score_item_template, type: :uuid, null: true
9
+ t.references :scorer, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.string :title, null: true, default: nil, limit: 200
13
+ t.decimal :score, null: false, default: 0.0, precision: 12, scale: 2
14
+ t.date :scored_on, null: false
15
+
16
+ t.text :description
17
+ t.text :instruction
18
+
19
+ t.column :state, 'char(1)', null: false, default: 'C'
20
+ t.datetime :opened_at, null: false, default: Time.utc(1970)
21
+ t.datetime :closed_at, null: false, default: Time.utc(3000)
22
+ t.boolean :defunct, null: false, default: false
23
+ t.jsonb :notation, null: false, default: {}
24
+
25
+ t.timestamps null: false
26
+
27
+ end
28
+
29
+ add_index :unidom_score_sheets, :score_sheet_id
30
+ add_index :unidom_score_sheets, :score_item_template_id
31
+ add_index :unidom_score_sheets, :scorer_id
32
+
33
+ end
34
+
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Score
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-score
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.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-11-08 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -44,10 +44,12 @@ files:
44
44
  - app/jobs/unidom/score/application_job.rb
45
45
  - app/mailers/unidom/score/application_mailer.rb
46
46
  - app/models/unidom/score/application_record.rb
47
+ - app/models/unidom/score/score_item.rb
47
48
  - app/models/unidom/score/score_sheet.rb
48
49
  - app/views/layouts/unidom/score/application.html.erb
49
50
  - config/routes.rb
50
51
  - db/migrate/20060111000000_create_unidom_score_sheets.rb
52
+ - db/migrate/20060112000000_create_unidom_score_items.rb
51
53
  - lib/tasks/score_tasks.rake
52
54
  - lib/unidom/score.rb
53
55
  - lib/unidom/score/engine.rb