Class: Pbw::Process

Inherits:
Rule
  • Object
show all
Defined in:
app/models/pbw/process.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.creatable_by?(user, subject) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/pbw/process.rb', line 10

def self.creatable_by?(user, subject)
    true
end

.deletable_by?(user, subject) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/pbw/process.rb', line 18

def self.deletable_by?(user, subject)
    user.admin?
end

.editable_by?(user, subject) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/pbw/process.rb', line 14

def self.editable_by?(user, subject)
    user.admin?
end

.viewable_by?(user, subject) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/models/pbw/process.rb', line 6

def self.viewable_by?(user, subject)
    user.admin?
end

Instance Method Details

#after_triggers(token_or_area) ⇒ Object



27
28
29
# File 'app/models/pbw/process.rb', line 27

def after_triggers(token_or_area)
	# stub method
end

#before_run(token_or_area) ⇒ Object



22
23
24
25
# File 'app/models/pbw/process.rb', line 22

def before_run(token_or_area)
	# stub method
	true
end

#changeset(token_or_area) ⇒ Object



31
32
33
34
# File 'app/models/pbw/process.rb', line 31

def changeset(token_or_area)
	# stub method
	Pbw::Changeset.new
end

#execute_changeset!(&changeset) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'app/models/pbw/process.rb', line 36

def execute_changeset!(&changeset)
	changeset.models_changed.each do |model|
		changes = changeset.changes_for_model(model)
		changes.keys.each do |field|
			model.send("#{field}=".to_sym,changes[field])
		end
		return false unless model.save
	end
	true
end

#run!(token_or_area) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'app/models/pbw/process.rb', line 47

def run!(token_or_area)
	return false unless before_run(token_or_area)
	changes = changeset(token_or_area)
	return false unless changes
	raise "Invalid object returned from changeset method in #{self.class.name}" unless changes.is_a?(Changeset)
	return false unless token_or_area.check_constraints_and_capabilities(changes)
	execute_changeset!(changes)
	token_or_area.check_triggers!
	after_triggers(token_or_area)
end