Class: Action
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Action
show all
- Includes:
- OhNoes::Destroy
- Defined in:
- app/models/action.rb
Constant Summary
collapse
- GIVE_TYPES =
Action types: give, go, do, get, join, hear
[ "Monetary", "In-Kind" ].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#destroy, #destroyable?
Class Method Details
.create_of_type(type) ⇒ Object
20
21
22
23
24
25
|
# File 'app/models/action.rb', line 20
def self.create_of_type(type)
case type
when "hear" then HearAction.new
when "give" then GiveAction.new
end
end
|
.from_open_struct(action_struct) ⇒ Object
96
97
98
99
100
101
102
|
# File 'app/models/action.rb', line 96
def self.from_open_struct(action_struct)
action = Kernel.const_get(action_struct.type).new
Kernel.const_get(action_struct.type).column_names.each do |col|
action.send("#{col}=", action_struct.send(col)) unless action_struct.send(col).nil?
end
action
end
|
.recent(organization, limit = 5) ⇒ Object
This returnes an ARel, so you can chain
74
75
76
|
# File 'app/models/action.rb', line 74
def self.recent(organization, limit = 5)
Action.includes(:person).where(:organization_id => organization).order('occurred_at DESC').limit(limit)
end
|
Instance Method Details
#full_details ⇒ Object
55
56
57
|
# File 'app/models/action.rb', line 55
def full_details
details
end
|
#give_action_subtypes ⇒ Object
78
79
80
|
# File 'app/models/action.rb', line 78
def give_action_subtypes
GIVE_TYPES
end
|
#hear_action_subtypes ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/action.rb', line 59
def hear_action_subtypes
[ "Email (sent)",
"Email (received)",
"Phone (initiated)",
"Phone (received)",
"Postal (sent)",
"Postal (received)",
"Meeting",
"Twitter",
"Facebook",
"Blog",
"Press" ]
end
|
#sentence ⇒ Object
51
52
53
|
# File 'app/models/action.rb', line 51
def sentence
(verb + " " + details.uncapitalize)
end
|
#set_creator(user) ⇒ Object
38
39
40
41
|
# File 'app/models/action.rb', line 38
def set_creator(user)
self.creator_id = user.id
self.organization_id = user.current_organization.id
end
|
#set_params(params, person) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'app/models/action.rb', line 27
def set_params(params, person)
params ||= {}
self.occurred_at = params[:occurred_at]
self.subtype = params[:subtype]
self.details = params[:details]
self.person = person
self.subject = person
end
|
#to_open_struct ⇒ Object
This exists solely so that DJ can serialize an unsaved action so that ActionJob can run There’s nothing inherent to Action in this method so it looks like a good candidate to move into a Module. But, I’m not thrilled with it and don’t want it used willy-nilly Perhaps in an DelayedJob::Unsaved::Serializable Module or something.
88
89
90
91
92
93
94
|
# File 'app/models/action.rb', line 88
def to_open_struct
action_struct = OpenStruct.new
self.class.column_names.each do |col|
action_struct.send("#{col}=", self.send(col))
end
action_struct
end
|
#unstarred? ⇒ Boolean
43
44
45
|
# File 'app/models/action.rb', line 43
def unstarred?
!starred?
end
|
#verb ⇒ Object
47
48
49
|
# File 'app/models/action.rb', line 47
def verb
""
end
|