Class: Runo::Workflow
- Inherits:
-
Object
show all
- Includes:
- I18n
- Defined in:
- lib/_workflow/_workflow.rb
Overview
- Author
-
Akira FUNAI
- Copyright
-
Copyright © 2009 Akira FUNAI
Defined Under Namespace
Classes: Attachment, Blog, Contact, Forum, Register
Constant Summary
collapse
- DEFAULT_META =
{
:item_label => Runo::I18n.n_('item', 'items', 1),
}
- DEFAULT_SUB_ITEMS =
{}
- ROLE_ADMIN =
0b10000
- ROLE_GROUP =
0b01000
- ROLE_OWNER =
0b00100
- ROLE_USER =
0b00010
- ROLE_NONE =
0b00001
- PERM =
{
:create => 0b11111,
:read => 0b11111,
:update => 0b11111,
:delete => 0b11111,
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from I18n
_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=
Constructor Details
#initialize(sd) ⇒ Workflow
Returns a new instance of Workflow.
45
46
47
|
# File 'lib/_workflow/_workflow.rb', line 45
def initialize(sd)
@sd = sd
end
|
Instance Attribute Details
#sd ⇒ Object
Returns the value of attribute sd.
43
44
45
|
# File 'lib/_workflow/_workflow.rb', line 43
def sd
@sd
end
|
Class Method Details
.instance(sd) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/_workflow/_workflow.rb', line 28
def self.instance(sd)
klass = sd[:workflow].to_s.capitalize
if klass != ''
self.const_get(klass).new sd
else
self.new sd
end
end
|
.roles(roles) ⇒ Object
37
38
39
40
41
|
# File 'lib/_workflow/_workflow.rb', line 37
def self.roles(roles)
%w(admin group owner user none).select {|r|
roles & const_get("ROLE_#{r.upcase}") > 0
}.collect{|r| Runo::I18n._ r }
end
|
Instance Method Details
#_get(arg) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/_workflow/_workflow.rb', line 65
def _get(arg)
@sd.instance_eval {
if arg[:action] == :create
item_instance '_001'
_get_by_tmpl({:action => :create, :conds => {:id => '_001'}}, my[:tmpl][:index])
end
}
end
|
#_hide?(arg) ⇒ Boolean
74
75
76
77
|
# File 'lib/_workflow/_workflow.rb', line 74
def _hide?(arg)
(arg[:p_action] && arg[:p_action] != :read) ||
(arg[:orig_action] == :read && arg[:action] == :submit)
end
|
#after_commit ⇒ Object
82
83
|
# File 'lib/_workflow/_workflow.rb', line 82
def after_commit
end
|
#before_commit ⇒ Object
79
80
|
# File 'lib/_workflow/_workflow.rb', line 79
def before_commit
end
|
#default_sub_items ⇒ Object
49
50
51
|
# File 'lib/_workflow/_workflow.rb', line 49
def default_sub_items
self.class.const_get :DEFAULT_SUB_ITEMS
end
|
#next_action(base) ⇒ Object
85
86
87
|
# File 'lib/_workflow/_workflow.rb', line 85
def next_action(base)
(!base.result || base.result.values.all? {|item| item.permit? :read }) ? :read_detail : :done
end
|
#permit?(roles, action) ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/_workflow/_workflow.rb', line 53
def permit?(roles, action)
case action
when :login, :done, :message
true
when :preview
(roles & self.class.const_get(:PERM)[:read].to_i) > 0
else
(roles & self.class.const_get(:PERM)[action].to_i) > 0
end
end
|