Class: User
- Inherits:
-
Object
- Object
- User
- Includes:
- GDS::SSO::User, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/user.rb
Class Method Summary collapse
-
.collection_name ⇒ Object
Let an app configure the collection name to use, e.g.
Instance Method Summary collapse
- #assign(edition, recipient) ⇒ Object
- #create_edition(format, attributes = {}) ⇒ Object
- #gravatar_url(opts = {}) ⇒ Object
- #new_version(edition, convert_to = nil) ⇒ Object
- #progress(edition, action_attributes) ⇒ Object
- #record_note(edition, comment, type = Action::NOTE) ⇒ Object
- #resolve_important_note(edition) ⇒ Object
- #to_s ⇒ Object
- #unassign(edition) ⇒ Object
Class Method Details
.collection_name ⇒ Object
Let an app configure the collection name to use, e.g. set a constant in an initializer
13 14 15 |
# File 'app/models/user.rb', line 13 def self.collection_name defined?(USER_COLLECTION_NAME) ? USER_COLLECTION_NAME : "users" end |
Instance Method Details
#assign(edition, recipient) ⇒ Object
73 74 75 |
# File 'app/models/user.rb', line 73 def assign(edition, recipient) GovukContentModels::ActionProcessors::AssignProcessor.new(self, edition, { recipient_id: recipient.id }).processed_edition end |
#create_edition(format, attributes = {}) ⇒ Object
65 66 67 |
# File 'app/models/user.rb', line 65 def create_edition(format, attributes = {}) GovukContentModels::ActionProcessors::CreateEditionProcessor.new(self, nil, {}, { format: format, edition_attributes: attributes }).processed_edition end |
#gravatar_url(opts = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/models/user.rb', line 40 def gravatar_url(opts = {}) opts.symbolize_keys! "%s.gravatar.com/avatar/%s%s" % [ opts[:ssl] ? "https://secure" : "http://www", Digest::MD5.hexdigest(email.downcase), opts[:s] ? "?s=#{CGI.escape(opts[:s])}" : "" ] end |
#new_version(edition, convert_to = nil) ⇒ Object
69 70 71 |
# File 'app/models/user.rb', line 69 def new_version(edition, convert_to = nil) GovukContentModels::ActionProcessors::NewVersionProcessor.new(self, edition, {}, { convert_to: convert_to }).processed_edition end |
#progress(edition, action_attributes) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/models/user.rb', line 49 def progress(edition, action_attributes) request_type = action_attributes.delete(:request_type) processor = GovukContentModels::ActionProcessors::REQUEST_TYPE_TO_PROCESSOR[request_type.to_sym] edition = GovukContentModels::ActionProcessors::const_get(processor).new(self, edition, action_attributes, {}).processed_edition edition.save if edition end |
#record_note(edition, comment, type = Action::NOTE) ⇒ Object
57 58 59 |
# File 'app/models/user.rb', line 57 def record_note(edition, comment, type = Action::NOTE) edition.new_action(self, type, comment: comment) end |
#resolve_important_note(edition) ⇒ Object
61 62 63 |
# File 'app/models/user.rb', line 61 def resolve_important_note(edition) record_note(edition, nil, Action::IMPORTANT_NOTE_RESOLVED) end |
#to_s ⇒ Object
36 37 38 |
# File 'app/models/user.rb', line 36 def to_s name || email || "" end |
#unassign(edition) ⇒ Object
77 78 79 |
# File 'app/models/user.rb', line 77 def unassign(edition) GovukContentModels::ActionProcessors::AssignProcessor.new(self, edition).processed_edition end |