Class: MessageRecipientQuery
- Inherits:
-
Object
- Object
- MessageRecipientQuery
- Defined in:
- app/models/message_recipient_query.rb
Defined Under Namespace
Classes: ModelIdNotFound
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#model ⇒ Object
Returns the value of attribute model.
-
#query ⇒ Object
Returns the value of attribute query.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query, type, id, model) ⇒ MessageRecipientQuery
constructor
A new instance of MessageRecipientQuery.
Constructor Details
#initialize(query, type, id, model) ⇒ MessageRecipientQuery
Returns a new instance of MessageRecipientQuery.
10 11 12 13 14 15 |
# File 'app/models/message_recipient_query.rb', line 10 def initialize(query, type, id, model) @query = query @type = type @id = id @model = model end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'app/models/message_recipient_query.rb', line 7 def id @id end |
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'app/models/message_recipient_query.rb', line 8 def model @model end |
#query ⇒ Object
Returns the value of attribute query.
5 6 7 |
# File 'app/models/message_recipient_query.rb', line 5 def query @query end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'app/models/message_recipient_query.rb', line 6 def type @type end |
Class Method Details
.friendly_name(query, model = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/message_recipient_query.rb', line 47 def self.friendly_name(query, model = nil) begin recipient_query = parse(query, model) model = recipient_query.model rescue MessageRecipientQuery::ModelIdNotFound return "[invalid recipient]" end case recipient_query.type when "bus-list" "Bus List: #{model.name} (signed up for bus)" when "bus-list--eligible" "Bus List: #{model.name} (eligible, not signed up for bus)" when "bus-list--applied" "Bus List: #{model.name} (applied/not accepted)" when "school" "Confirmed or Accepted: #{model.name}" else raise "Unknown recipient query type: #{recipient_query.type.inspect} (in message recipient query: #{r.inspect}" end end |
.parse(query, model = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/message_recipient_query.rb', line 17 def self.parse(query, model = nil) # Format: # model::ID # model--modifier::ID match = query.match(/(.*)::(\d*)/) type = match[1] id = match[2] # Find the backing database model, ensuring the given ID exists for that model. model_name = nil case type when "bus-list", "bus-list--applied", "bus-list--eligible" model ||= BusList.find_by_id(id) model_name = "Bus List" when "school" model ||= School.find_by_id(id) model_name = "School" else raise "Unknown recipient query type: #{type.inspect} (in message recipient query: #{query.inspect}" end raise MessageRecipientQuery::ModelIdNotFound, "Could not find #{model_name} with ID #{id.inspect} (in message recipient query: #{query.inspect})" if model.blank? MessageRecipientQuery.new( query, type, id, model ) end |