unidom-order 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d0dba16e038c6aeccd88b27e454be0649130991
4
+ data.tar.gz: aa0003a76a2d27a4430d448be1c2521ba0154fd3
5
+ SHA512:
6
+ metadata.gz: f8d0610e186cadf00aa653cb8e6d4c0a8acb8e4b7b5867c76cbb2c43bcaad483e6165a67873501b159670eacf3675a65760dc1873b2f00e8fa3c3df6481d57e1
7
+ data.tar.gz: 6b455500cdefc76ef655358587788c5530fc836b5cf521cc37d8d459528908ee8c29b4e633beb61d2a61be0f61c82f3a7b05c6eddb3d522b0cc0532d902b07bd
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Topbit Du
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Unidom Order 订单领域模型引擎
2
+
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+
5
+ Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Order domain model engine includes Order, Order Item, and Order Adjustment models.
6
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。订单领域模型引擎包括订单、订单项和订单调整的模型。
7
+
8
+ ## Usage in Gemfile:
9
+ ```ruby
10
+ gem 'unidom-order'
11
+ ```
12
+
13
+ ## Run the Database Migration:
14
+ ```shell
15
+ rake db:migrate
16
+ ```
17
+
18
+ ## Call the Model:
19
+ ```ruby
20
+ order = Unidom::Order::Order.valid_at.alive.first
21
+ order.items.valid_at.alive
22
+ order.adjustments.valid_at.alive
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Unidom Order'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Unidom::Order::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module Unidom::Order::ApplicationHelper
2
+ end
@@ -0,0 +1,20 @@
1
+ # Order 是订单。
2
+
3
+ class Unidom::Order::Order < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_orders'
6
+
7
+ validates :number, presence: true, length: { is: self.columns_hash['number'].limit }
8
+ validates :purchase_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
9
+ validates :aggregate_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
10
+
11
+ belongs_to :placer, polymorphic: true
12
+ belongs_to :taker, polymorphic: true
13
+
14
+ has_many :items, class_name: 'Unidom::Order::OrderItem', as: :order
15
+ has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted
16
+
17
+ scope :placed_by, ->(placer) { where placer: placer }
18
+ scope :taken_by, ->(taker) { where taker: taker }
19
+
20
+ end
@@ -0,0 +1,13 @@
1
+ # Order Adjustment 是订单调整项。
2
+
3
+ class Unidom::Order::OrderAdjustment < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_order_adjustments'
6
+
7
+ validates :amount, presence: true, numericality: { less_than: 1000000000, greater_than: -1000000000 }
8
+
9
+ belongs_to :adjusted, polymorphic: true
10
+
11
+ scope :adjusted_by, ->(adjusted) { where adjusted: adjusted }
12
+
13
+ end
@@ -0,0 +1,23 @@
1
+ # Order Item 是订单项。
2
+
3
+ class Unidom::Order::OrderItem < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_order_items'
6
+
7
+ validates :ordinal, presence: true, numericality: { only_integer: true, greater_than: 0, less_than: 1000000000 }
8
+ validates :unit_price, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
9
+ validates :quantity, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
10
+ validates :purchase_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
11
+ validates :subtotal_amount, presence: true, numericality: { less_than: 1000000000, greater_than: 0 }
12
+
13
+ belongs_to :order, class_name: 'Unidom::Order::Order'
14
+ belongs_to :ordered, polymorphic: true
15
+ belongs_to :placer, polymorphic: true
16
+
17
+ has_many :adjustments, class_name: 'Unidom::Order::OrderAdjustment', as: :adjusted
18
+
19
+ scope :order_is, ->(order) { where order_id: (order.respond_to?(:id) ? order.id : order) }
20
+ scope :ordered_is, ->(ordered) { where ordered: ordered }
21
+ scope :placed_by, ->(placer) { where placer: placer }
22
+
23
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Order</title>
5
+ <%= stylesheet_link_tag "order/application", media: "all" %>
6
+ <%= javascript_include_tag "order/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Unidom::Order::Engine.routes.draw do
2
+ end
@@ -0,0 +1,38 @@
1
+ class CreateUnidomOrders < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_orders, id: :uuid do |t|
6
+
7
+ t.references :placer, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :taker, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+
12
+ t.column :number, 'char(12)', null: false, default: '0'*12
13
+
14
+ t.decimal :purchase_amount, null: false, default: 0.0, precision: 12, scale: 2
15
+ t.decimal :aggregate_amount, null: false, default: 0.0, precision: 12, scale: 2
16
+
17
+ t.text :instruction
18
+ t.text :description
19
+
20
+ t.string :slug, null: false, default: nil, limit: 200
21
+ t.column :state, 'char(1)', null: false, default: 'C'
22
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
23
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
24
+ t.boolean :defunct, null: false, default: false
25
+ t.jsonb :notation, null: false, default: {}
26
+
27
+ t.timestamps null: false
28
+
29
+ end
30
+
31
+ add_index :unidom_orders, :placer_id
32
+ add_index :unidom_orders, :taker_id
33
+ add_index :unidom_orders, :slug, unique: true
34
+ add_index :unidom_orders, :number, unique: true
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,41 @@
1
+ # Order Item 是订单项。
2
+
3
+ class CreateUnidomOrderItems < ActiveRecord::Migration
4
+
5
+ def change
6
+
7
+ create_table :unidom_order_items, id: :uuid do |t|
8
+
9
+ t.references :order, type: :uuid, null: false
10
+ t.references :ordered, type: :uuid, null: false,
11
+ polymorphic: { null: false, default: '', limit: 200 }
12
+ t.references :placer, type: :uuid, null: false,
13
+ polymorphic: { null: false, default: '', limit: 200 }
14
+
15
+ t.integer :ordinal, null: false, default: 0
16
+
17
+ t.decimal :unit_price, null: false, default: 0.0, precision: 12, scale: 2
18
+ t.decimal :quantity, null: false, default: 0.0, precision: 12, scale: 2
19
+ t.decimal :purchase_amount, null: false, default: 0.0, precision: 12, scale: 2
20
+ t.decimal :subtotal_amount, null: false, default: 0.0, precision: 12, scale: 2
21
+
22
+ t.text :instruction
23
+ t.text :description
24
+
25
+ t.column :state, 'char(1)', null: false, default: 'C'
26
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
27
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
28
+ t.boolean :defunct, null: false, default: false
29
+ t.jsonb :notation, null: false, default: {}
30
+
31
+ t.timestamps null: false
32
+
33
+ end
34
+
35
+ add_index :unidom_order_items, :order_id
36
+ add_index :unidom_order_items, :ordered_id
37
+ add_index :unidom_order_items, :placer_id
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,32 @@
1
+ class CreateUnidomOrderAdjustments < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_order_adjustments, id: :uuid do |t|
6
+
7
+ t.references :adjusted, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+
10
+ t.column :adjustment_factor_code, 'char(4)', null: false, default: 'FRGT'
11
+ t.column :calculation_code, 'char(4)', null: false, default: 'AMNT'
12
+
13
+ t.decimal :amount, null: false, default: 0.0, precision: 12, scale: 2
14
+
15
+ t.text :instruction
16
+ t.text :description
17
+
18
+ t.column :state, 'char(1)', null: false, default: 'C'
19
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
20
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
21
+ t.boolean :defunct, null: false, default: false
22
+ t.jsonb :notation, null: false, default: {}
23
+
24
+ t.timestamps null: false
25
+
26
+ end
27
+
28
+ add_index :unidom_order_adjustments, :adjusted_id
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :order do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,15 @@
1
+ module Unidom
2
+ module Order
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ isolate_namespace ::Unidom::Order
7
+
8
+ initializer :append_migrations do |app|
9
+ config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Unidom
2
+ module Order
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'unidom/order/engine'
2
+
3
+ module Unidom
4
+ module Order
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unidom-order
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unidom-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
+ The Order domain model engine includes Order, Order Item, and Order Adjustment models.
29
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。订单领域模型引擎包括订单、订单项和订单调整的模型。
30
+ email:
31
+ - topbit.du@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/javascripts/unidom/order/application.js
40
+ - app/assets/stylesheets/unidom/order/application.css
41
+ - app/controllers/unidom/order/application_controller.rb
42
+ - app/helpers/unidom/order/application_helper.rb
43
+ - app/models/unidom/order/order.rb
44
+ - app/models/unidom/order/order_adjustment.rb
45
+ - app/models/unidom/order/order_item.rb
46
+ - app/views/layouts/unidom/order/application.html.erb
47
+ - config/routes.rb
48
+ - db/migrate/20020601000000_create_unidom_orders.rb
49
+ - db/migrate/20020602000000_create_unidom_order_items.rb
50
+ - db/migrate/20020603000000_create_unidom_order_adjustments.rb
51
+ - lib/tasks/order_tasks.rake
52
+ - lib/unidom/order.rb
53
+ - lib/unidom/order/engine.rb
54
+ - lib/unidom/order/version.rb
55
+ homepage: https://github.com/topbitdu/unidom-order
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: The Order domain model engine includes Order, Order Item, and Order Adjustment
79
+ models.
80
+ test_files: []