canmoia 0.0.1
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 +7 -0
- data/Guardfile +30 -0
- data/README.md +186 -0
- data/Rakefile +27 -0
- data/WTFP-LICENSE +13 -0
- data/lib/canmoia/concerns/notification.rb~ +38 -0
- data/lib/canmoia/concerns/order.rb +71 -0
- data/lib/canmoia/concerns/order.rb~ +65 -0
- data/lib/canmoia/concerns/work.rb +21 -0
- data/lib/canmoia/concerns/work.rb~ +33 -0
- data/lib/canmoia/features/notification.rb +51 -0
- data/lib/canmoia/features/notification.rb~ +38 -0
- data/lib/canmoia/tasks/install.rb.erb +23 -0
- data/lib/canmoia/version.rb +3 -0
- data/lib/canmoia.rb +8 -0
- data/lib/canmoia.rb~ +6 -0
- data/lib/tasks/canmoia_tasks.rake +4 -0
- data/lib/tasks/canmoia_tasks.rb.erb +16 -0
- data/spec/concerns/order_spec.rb +45 -0
- data/spec/concerns/order_spec.rb~ +41 -0
- data/spec/concerns/work_spec.rb +32 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/notifiable_order_mailer.rb~ +14 -0
- data/spec/dummy/app/mailers/work_order_mailer.rb +14 -0
- data/spec/dummy/app/mailers/work_order_mailer.rb~ +14 -0
- data/spec/dummy/app/models/employee.rb +4 -0
- data/spec/dummy/app/models/employee.rb~ +3 -0
- data/spec/dummy/app/models/item.rb +5 -0
- data/spec/dummy/app/models/order.rb +4 -0
- data/spec/dummy/app/models/order.rb~ +4 -0
- data/spec/dummy/app/models/user.rb +6 -0
- data/spec/dummy/app/models/user.rb~ +4 -0
- data/spec/dummy/app/models/work_order.rb +4 -0
- data/spec/dummy/app/models/work_order.rb~ +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/work_order_mailer/close_notification_to_responsible.text.erb +3 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/application.rb~ +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environment.rb~ +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/development.rb~ +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/environments/test.rb~ +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/mongoid.yml +68 -0
- data/spec/dummy/config/mongoid.yml~ +68 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1 -0
- data/spec/dummy/log/test.log +4574 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/fixtures/work_order_mailer/close_notification_to_responsible +3 -0
- data/spec/dummy/spec/mailers/notifiable_order_mailer_spec.rb~ +18 -0
- data/spec/dummy/spec/mailers/work_order_mailer_spec.rb +19 -0
- data/spec/dummy/spec/mailers/work_order_mailer_spec.rb~ +20 -0
- data/spec/fabricators/item_fabricator.rb +5 -0
- data/spec/fabricators/item_fabricator.rb~ +5 -0
- data/spec/fabricators/order_fabricator.rb +15 -0
- data/spec/fabricators/order_fabricator.rb~ +9 -0
- data/spec/fabricators/user_fabricator.rb +7 -0
- data/spec/fabricators/user_fabricator.rb~ +7 -0
- data/spec/spec_helper.rb +50 -0
- data/spec/spec_helper.rb~ +34 -0
- data/spec/support/concern_macros.rb +0 -0
- data/spec/support/fabrication.rb +8 -0
- data/spec/support/fabricator.rb +5 -0
- data/spec/support/mailer_macros.rb +9 -0
- metadata +437 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e32b4b89e98944da5607f61c21ef58cf8b2ab1e5
|
|
4
|
+
data.tar.gz: 07f3260fddc77f8d5a45328a50a91fedce11290f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6d0d92901045552b14bb859e4ff04936d006bae028bdd02ee15c8658607f9ea9db6e12b2fa6c965b45209eca322accd55ee4d3b7cde22acda36c658c7c2120bf
|
|
7
|
+
data.tar.gz: 13c93f718d7d5413eb7123e4a3f9f942cd953f27a1ee8ec39e6c7ca6cb4ee9707963eba80f5c45f616fa0620342371d4536415b3c8f378c1461c92b0e9870fca
|
data/Guardfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
guard :rspec do
|
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
|
8
|
+
|
|
9
|
+
# Rails example
|
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
|
16
|
+
|
|
17
|
+
# Canmoia Concerns
|
|
18
|
+
watch(%r{^lib/canmoia/concerns(.+)\.rb$}) { |m| ["spec/#{m[1]}_spec.rb", "spec/lib/concerns/#{m[1]}_spec.rb"] }
|
|
19
|
+
watch(%r{^lib/canmoia/features(.+)\.rb$}) { |m| ["spec/#{m[1]}_spec.rb", "spec/lib/features/#{m[1]}_spec.rb"] }
|
|
20
|
+
|
|
21
|
+
# Fabricators
|
|
22
|
+
watch(%r{^spec/fabricators/(.+)\.rb$}) { |m| ["spec/#{m[1]}_spec.rb", "spec/concerns/#{m[1]}_spec.rb", "spec/models/#{m[1]}_spec.rb"] }
|
|
23
|
+
|
|
24
|
+
# Capybara features specs
|
|
25
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
|
26
|
+
|
|
27
|
+
# Turnip features and steps
|
|
28
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
|
29
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
|
30
|
+
end
|
data/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Canmöia
|
|
2
|
+
=======
|
|
3
|
+
|
|
4
|
+
<!---
|
|
5
|
+
|
|
6
|
+
TODO Add badges of this services
|
|
7
|
+
|
|
8
|
+
[](http://travis-ci.org/indefinido/canmoia)
|
|
9
|
+
[](https://coveralls.io/r/indefinido/canmoia)
|
|
10
|
+
[](https://codeclimate.com/github/indefinido/canmoia)
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
-->
|
|
14
|
+
|
|
15
|
+
Summary
|
|
16
|
+
-------
|
|
17
|
+
|
|
18
|
+
Canmöia (can = order, möia = work, work order). The core functionality of the [Order domain](http://en.wikipedia.org/wiki/Work_order)
|
|
19
|
+
|
|
20
|
+
Requirements
|
|
21
|
+
------------
|
|
22
|
+
|
|
23
|
+
- ruby 2.0.0
|
|
24
|
+
- workflow
|
|
25
|
+
- currently only support mongoid models
|
|
26
|
+
|
|
27
|
+
Getting Started
|
|
28
|
+
---------------
|
|
29
|
+
|
|
30
|
+
Add to your Gemfile:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem 'canmoia'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You must have a **model named User** and a **model named Item** for this to
|
|
37
|
+
work properly. Then add the concern you want to your model:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
class Order
|
|
41
|
+
include Mongoid::Document
|
|
42
|
+
include Canmoia::Order
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
You now have a fully working Order:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
order = Order.new
|
|
51
|
+
order.items << Item.new(value: 100)
|
|
52
|
+
order.items << Item.new(value: 150)
|
|
53
|
+
|
|
54
|
+
# Automatically computes total upon validation
|
|
55
|
+
order.valid?
|
|
56
|
+
order.total # 250.00
|
|
57
|
+
|
|
58
|
+
# Manage basic order states (workflow gem basics)
|
|
59
|
+
# To override behaviour just define close! method on model
|
|
60
|
+
order.close!
|
|
61
|
+
order.closed? # true
|
|
62
|
+
|
|
63
|
+
order.accept!
|
|
64
|
+
order.accepted? # true
|
|
65
|
+
order.state # accepted
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Automagically generated associations
|
|
69
|
+
order.client # your User model
|
|
70
|
+
order.items # your Item model
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
You might also try the Work Order concern:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
class Order
|
|
77
|
+
include Mongoid::Document
|
|
78
|
+
# Canmoia::Order is automatically included
|
|
79
|
+
include Canmoia::Work
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Automagically generated associations
|
|
83
|
+
order.responsible
|
|
84
|
+
|
|
85
|
+
# Autmatically notifications!
|
|
86
|
+
# When closing a order:
|
|
87
|
+
order.close!
|
|
88
|
+
|
|
89
|
+
# Canmoia will automatically try to notify
|
|
90
|
+
# the domain resposables for the event
|
|
91
|
+
# Trigerring this methods:
|
|
92
|
+
# OrderMailer.close_notification_to_responsible(order, order.responsible).deliver
|
|
93
|
+
# OrderMailer.close_notification_to_client(order, order.client).deliver
|
|
94
|
+
#
|
|
95
|
+
# Generalizing:
|
|
96
|
+
# #{YourModel}Mailer.#{event}_notification_to_#{recipient}
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Documentation
|
|
101
|
+
-------------
|
|
102
|
+
|
|
103
|
+
Sometime on the future might be a wiki page
|
|
104
|
+
|
|
105
|
+
### Concerns
|
|
106
|
+
#### Order (Canmoia::Order)
|
|
107
|
+
|
|
108
|
+
The current states and transitions are:
|
|
109
|
+
<sup>Order will always start at opened state (italics)</sup>
|
|
110
|
+
|
|
111
|
+
| state | event | transitions to |
|
|
112
|
+
|:-----------:|:--------:|:--------------:|
|
|
113
|
+
| *opened* | close | reviewing |
|
|
114
|
+
| *opened* | cancel | canceled |
|
|
115
|
+
| reviewing | accept | accepted |
|
|
116
|
+
| reviewing | reject | rejected |
|
|
117
|
+
| reviewing | cancel | canceled |
|
|
118
|
+
| accepted | complete | completed |
|
|
119
|
+
| accepted | cancel | canceled |
|
|
120
|
+
| rejected | complete | completed |
|
|
121
|
+
| rejected | cancel | canceled |
|
|
122
|
+
| completed | - | - |
|
|
123
|
+
| canceled | - | - |
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
#### Work Order (Canmoia::Work)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
You can specify to which events canmöia should send notifications:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
class Order
|
|
133
|
+
include Mongoid::Document
|
|
134
|
+
# Canmoia::Order is automatically included
|
|
135
|
+
include Canmoia::Work
|
|
136
|
+
|
|
137
|
+
# BTW this are the defaults!
|
|
138
|
+
notify :responsible, :on => [:open, :close]
|
|
139
|
+
notify :client , :on => [:open, :accept, :reject, :cancel]
|
|
140
|
+
end
|
|
141
|
+
```
|
|
142
|
+
### Features
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
#### Notification (Canmoia::Notification)
|
|
146
|
+
Include workflow and rock with only notification functionalities!
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
class Order
|
|
150
|
+
include Mongoid::Document
|
|
151
|
+
include Workflow
|
|
152
|
+
include Canmoia::Notification
|
|
153
|
+
|
|
154
|
+
workflow do
|
|
155
|
+
|
|
156
|
+
state :opened do
|
|
157
|
+
event :close, :transitions_to => :checkout
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
state :checkout
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Remember, will trigger: OrderMailer.close_notification_to_responsible(order, order.responsible).deliver
|
|
165
|
+
notify :responsible, :on => :close
|
|
166
|
+
end
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
TODO
|
|
171
|
+
----
|
|
172
|
+
|
|
173
|
+
### Mail Generator
|
|
174
|
+
Automatically add default mail templates for notification kinds to the view_path
|
|
175
|
+
|
|
176
|
+
### Purchase Order
|
|
177
|
+
Add suport for Purchase Order Concern (Canmoia::Purchasable)
|
|
178
|
+
|
|
179
|
+
### Reviewable Feature
|
|
180
|
+
Extract review order feature from Order concern (Canmoia::Reviewable)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
This project rocks and uses WTFP-LICENSE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'Canmoia'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Bundler::GemHelper.install_tasks
|
|
27
|
+
|
data/WTFP-LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
2
|
+
Version 2, December 2004
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
|
7
|
+
copies of this license document, and changing it is allowed as long
|
|
8
|
+
as the name is changed.
|
|
9
|
+
|
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
12
|
+
|
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Canmoia::Notification
|
|
2
|
+
|
|
3
|
+
def notify entity_name = :responsible, on: -> { raise "on is required" }, via: :email
|
|
4
|
+
raise "Recipient named as '#{entity_name}' not found for #{self.name}" unless instance_methods.include? entity_name.to_sym
|
|
5
|
+
|
|
6
|
+
on.each do |event|
|
|
7
|
+
add_notification_method event, entity_name, via
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
# TODO use method missing
|
|
14
|
+
def add_notification_method event, entity_name, via
|
|
15
|
+
mail_method = "#{event}_notification_to_#{entity_name}"
|
|
16
|
+
|
|
17
|
+
define_method "#{event}!" do |*args|
|
|
18
|
+
returned = super *args
|
|
19
|
+
# TODO better error message when mailer is not found
|
|
20
|
+
# TODO allow specification of custom mailer
|
|
21
|
+
mailer = "#{self.class.name}Mailer".classify.constantize
|
|
22
|
+
|
|
23
|
+
# TODO better error message when mail method is not found
|
|
24
|
+
entity = send entity_name
|
|
25
|
+
mail = mailer.send mail_method, self, entity
|
|
26
|
+
|
|
27
|
+
mail.deliver or returned
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# - on :open , close: :reviewing, cancel: :canceled, notify: :responsible
|
|
32
|
+
# V on :review, reject: :rejected, accept: :accepted
|
|
33
|
+
# - on :accept, notify: :buyer
|
|
34
|
+
# - on :reject, notify: :buyer
|
|
35
|
+
# - on :cancel, notify: [:buyer, via: :email] }
|
|
36
|
+
# - on :finish, notify: [:buyer, via: :email] }
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Order
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include ::Workflow
|
|
9
|
+
include CalculationMethods
|
|
10
|
+
# extend Notification
|
|
11
|
+
|
|
12
|
+
# Fields
|
|
13
|
+
# TODO move to Canmoia::Purchase
|
|
14
|
+
field :state, type: Symbol
|
|
15
|
+
field :total, type: Float
|
|
16
|
+
|
|
17
|
+
# Relations
|
|
18
|
+
embeds_many :items
|
|
19
|
+
|
|
20
|
+
# TODO move to Canmoia::Purchase
|
|
21
|
+
has_one :client, :class_name => "::User"
|
|
22
|
+
|
|
23
|
+
# Domain Callbacks
|
|
24
|
+
before_validation :calculate_total, :if => :opened?
|
|
25
|
+
|
|
26
|
+
# States
|
|
27
|
+
workflow_column :state
|
|
28
|
+
workflow do
|
|
29
|
+
|
|
30
|
+
state :opened do
|
|
31
|
+
event :close , transitions_to: :reviewing
|
|
32
|
+
event :cancel, transitions_to: :canceled
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
state :reviewing do
|
|
36
|
+
event :accept, transitions_to: :accepted
|
|
37
|
+
event :reject, transitions_to: :rejected
|
|
38
|
+
|
|
39
|
+
event :cancel, transitions_to: :canceled
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
state :accepted do
|
|
43
|
+
event :complete, transitions_to: :completed
|
|
44
|
+
event :cancel , transitions_to: :canceled
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
state :rejected do
|
|
48
|
+
event :complete, transitions_to: :completed
|
|
49
|
+
event :cancel , transitions_to: :canceled
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
state :completed
|
|
53
|
+
state :canceled
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
module CalculationMethods
|
|
58
|
+
def calculate_total
|
|
59
|
+
self.total = items.sum &:value
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# - on :open , close: :reviewing, cancel: :canceled, notify: :responsible
|
|
64
|
+
# V on :review, reject: :rejected, accept: :accepted
|
|
65
|
+
# - on :accept, notify: :buyer
|
|
66
|
+
# - on :reject, notify: :buyer
|
|
67
|
+
# - on :cancel, notify: [:buyer, via: :email] }
|
|
68
|
+
# - on :finish, notify: [:buyer, via: :email] }
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Order
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include ::Workflow
|
|
9
|
+
include CalculationMethods
|
|
10
|
+
# extend Notification
|
|
11
|
+
|
|
12
|
+
# Fields
|
|
13
|
+
field :total, type: Float
|
|
14
|
+
field :state, type: Symbol
|
|
15
|
+
|
|
16
|
+
# Relations
|
|
17
|
+
embeds_many :items
|
|
18
|
+
has_one :client, :class_name => "::User"
|
|
19
|
+
|
|
20
|
+
# States
|
|
21
|
+
workflow_column :state
|
|
22
|
+
workflow do
|
|
23
|
+
|
|
24
|
+
state :opened do
|
|
25
|
+
event :close , transitions_to: :reviewing
|
|
26
|
+
event :cancel, transitions_to: :canceled
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
state :reviewing do
|
|
30
|
+
event :accept, transitions_to: :accepted
|
|
31
|
+
event :reject, transitions_to: :rejected
|
|
32
|
+
|
|
33
|
+
event :cancel, transitions_to: :canceled
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
state :accepted do
|
|
37
|
+
event :complete, transitions_to: :completed
|
|
38
|
+
event :cancel , transitions_to: :canceled
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
state :rejected do
|
|
42
|
+
event :complete, transitions_to: :completed
|
|
43
|
+
event :cancel , transitions_to: :canceled
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
state :completed
|
|
47
|
+
state :canceled
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module CalculationMethods
|
|
52
|
+
def total
|
|
53
|
+
@total ||= super or items.sum(&:value)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# - on :open , close: :reviewing, cancel: :canceled, notify: :responsible
|
|
58
|
+
# V on :review, reject: :rejected, accept: :accepted
|
|
59
|
+
# - on :accept, notify: :buyer
|
|
60
|
+
# - on :reject, notify: :buyer
|
|
61
|
+
# - on :cancel, notify: [:buyer, via: :email] }
|
|
62
|
+
# - on :finish, notify: [:buyer, via: :email] }
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Work
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Order
|
|
9
|
+
extend Notification
|
|
10
|
+
|
|
11
|
+
# Fields
|
|
12
|
+
|
|
13
|
+
# Relations
|
|
14
|
+
belongs_to :responsible, :class_name => "::User"
|
|
15
|
+
|
|
16
|
+
# States Notifications
|
|
17
|
+
notify :responsible, :on => [:open, :close]
|
|
18
|
+
notify :client , :on => [:open, :accept, :reject, :cancel]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Work
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
include Order
|
|
9
|
+
|
|
10
|
+
# Fields
|
|
11
|
+
|
|
12
|
+
# Relations
|
|
13
|
+
belongs_to :responsible, :class_name => "::User"
|
|
14
|
+
|
|
15
|
+
# States Notifications
|
|
16
|
+
notify :responsible
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module CalculationMethods
|
|
20
|
+
def total
|
|
21
|
+
@total ||= items.sum(&:value)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# - on :open , close: :reviewing, cancel: :canceled, notify: :responsible
|
|
26
|
+
# V on :review, reject: :rejected, accept: :accepted
|
|
27
|
+
# - on :accept, notify: :buyer
|
|
28
|
+
# - on :reject, notify: :buyer
|
|
29
|
+
# - on :cancel, notify: [:buyer, via: :email] }
|
|
30
|
+
# - on :finish, notify: [:buyer, via: :email] }
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Notification
|
|
5
|
+
# TODO add when needed extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
attr_accessor :notifications_declared
|
|
8
|
+
|
|
9
|
+
def self.extended base
|
|
10
|
+
base.notifications_declared = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def notify recipient_attribute = :responsible, on: -> { raise "on is required" }, via: :email
|
|
14
|
+
raise "Recipient named as '#{recipient_attribute}' not found for #{self.name}" unless instance_methods.include? recipient_attribute.to_sym
|
|
15
|
+
|
|
16
|
+
on.each do |event|
|
|
17
|
+
add_notification_method event, recipient_attribute, via
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# TODO use method missing
|
|
24
|
+
def add_notification_method event, recipient_attribute, via
|
|
25
|
+
mail_method = "#{event}_notification_to_#{recipient_attribute}"
|
|
26
|
+
|
|
27
|
+
notification = "#{event}_#{recipient_attribute}".to_sym
|
|
28
|
+
unless notifications_declared.include? notification
|
|
29
|
+
notifications_declared << notification
|
|
30
|
+
else
|
|
31
|
+
raise "Notification for event '#{event}' to recipient '#{recipient_attribute}' already declared!"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# TODO only define notification method if method is present on mailer
|
|
35
|
+
# TODO create task to generate / update mailer with notification settings
|
|
36
|
+
|
|
37
|
+
define_method "#{event}!" do |*args|
|
|
38
|
+
returned = super *args
|
|
39
|
+
# TODO better error message when mailer is not found
|
|
40
|
+
# TODO allow specification of custom mailer
|
|
41
|
+
mailer = "#{self.class.name}Mailer".classify.constantize
|
|
42
|
+
|
|
43
|
+
# TODO better error message when mail method is not found
|
|
44
|
+
entity = send recipient_attribute
|
|
45
|
+
mail = mailer.send mail_method, self, entity
|
|
46
|
+
|
|
47
|
+
mail.deliver or returned
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Canmoia
|
|
4
|
+
module Notification
|
|
5
|
+
# TODO add when needed extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
def notify entity_name = :responsible, on: -> { raise "on is required" }, via: :email
|
|
8
|
+
raise "Recipient named as '#{entity_name}' not found for #{self.name}" unless instance_methods.include? entity_name.to_sym
|
|
9
|
+
|
|
10
|
+
on.each do |event|
|
|
11
|
+
add_notification_method event, entity_name, via
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
# TODO use method missing
|
|
18
|
+
def add_notification_method event, entity_name, via
|
|
19
|
+
mail_method = "#{event}_notification_to_#{entity_name}"
|
|
20
|
+
|
|
21
|
+
# TODO only define notification method if method is present on mailer
|
|
22
|
+
# TODO create task to generate / update mailer with notification settings
|
|
23
|
+
|
|
24
|
+
define_method "#{event}!" do |*args|
|
|
25
|
+
returned = super *args
|
|
26
|
+
# TODO better error message when mailer is not found
|
|
27
|
+
# TODO allow specification of custom mailer
|
|
28
|
+
mailer = "#{self.class.name}Mailer".classify.constantize
|
|
29
|
+
|
|
30
|
+
# TODO better error message when mail method is not found
|
|
31
|
+
entity = send entity_name
|
|
32
|
+
mail = mailer.send mail_method, self, entity
|
|
33
|
+
|
|
34
|
+
mail.deliver or returned
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Canmoia
|
|
2
|
+
module Tasks
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
class Install < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Sample installation task
|
|
9
|
+
# def copy_initializer_file
|
|
10
|
+
# template 'canmoia.rb', 'config/initializers/canmoia.rb'
|
|
11
|
+
# end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
def self.add_templates_path!
|
|
15
|
+
current_directory = File.dirname(__FILE__)
|
|
16
|
+
source_paths << File.join(current_directory, 'templates')
|
|
17
|
+
source_paths << File.expand_path(File.join current_directory, '..', '..', '..')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
add_templates_path!
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/canmoia.rb
ADDED
data/lib/canmoia.rb~
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require File.expand_path('../../canmoia/tasks/install', __FILE__)
|
|
2
|
+
|
|
3
|
+
namespace :canmoia do
|
|
4
|
+
# Example install task
|
|
5
|
+
# desc "Install canmoia"
|
|
6
|
+
# task :install do
|
|
7
|
+
# Canmoia::Tasks::Install.start # Execute all install tasks
|
|
8
|
+
# end
|
|
9
|
+
|
|
10
|
+
# Example update task
|
|
11
|
+
# desc "Update canmoia"
|
|
12
|
+
# task :update do
|
|
13
|
+
# installation = Canmoia::Tasks::Install.new # Execute some install tasks
|
|
14
|
+
# installation.copy_initializer_file
|
|
15
|
+
# end
|
|
16
|
+
end
|