Class: WorkValidator
- Inherits:
-
Object
- Object
- WorkValidator
- Defined in:
- app/services/work_validator.rb
Instance Attribute Summary collapse
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Instance Method Summary collapse
-
#initialize(work) ⇒ WorkValidator
constructor
A new instance of WorkValidator.
- #valid? ⇒ Boolean
- #valid_datacite? ⇒ Boolean
- #valid_to_approve(user) ⇒ Object
- #valid_to_complete(*args) ⇒ Object
- #valid_to_draft ⇒ Object
- #valid_to_submit(*args) ⇒ Object
Constructor Details
#initialize(work) ⇒ WorkValidator
Returns a new instance of WorkValidator.
9 10 11 |
# File 'app/services/work_validator.rb', line 9 def initialize(work) @work = work end |
Instance Attribute Details
#work ⇒ Object (readonly)
Returns the value of attribute work.
4 5 6 |
# File 'app/services/work_validator.rb', line 4 def work @work end |
Instance Method Details
#valid? ⇒ Boolean
13 14 15 16 17 18 19 20 21 |
# File 'app/services/work_validator.rb', line 13 def valid? if work.none? validate_ids elsif work.draft? valid_to_draft else valid_to_submit end end |
#valid_datacite? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/services/work_validator.rb', line 60 def valid_datacite? datacite_serialization = resource.datacite_serialization datacite_serialization.valid? datacite_serialization.errors.each { |error| errors.add(:base, error) } errors.count == 0 rescue ArgumentError => error argument_path = error.backtrace_locations.first.path argument_file = argument_path.split("/").last argument_name = argument_file.split(".").first errors.add(:base, "#{argument_name.titleize}: #{error.}") false end |
#valid_to_approve(user) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/work_validator.rb', line 45 def valid_to_approve(user) if resource.doi.blank? errors.add :base, "DOI must be present for a work to be approved" end valid_to_submit(user) unless user.has_role? :group_admin, group errors.add :base, "Unauthorized to Approve" end validate_files if pre_curation_uploads.empty? && post_curation_uploads.empty? errors.add(:base, "You must include at least one file. <a href='#{work_file_upload_path(work)}'>Please upload one</a>") end errors.count == 0 end |
#valid_to_complete(*args) ⇒ Object
31 32 33 34 |
# File 'app/services/work_validator.rb', line 31 def valid_to_complete(*args) validate_files valid_to_submit(args) end |
#valid_to_draft ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/services/work_validator.rb', line 23 def valid_to_draft(*) errors.add(:base, "Must provide a title") if resource.main_title.blank? validate_ark validate_creators if resource.present? && !resource..empty? errors.count == 0 end |
#valid_to_submit(*args) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'app/services/work_validator.rb', line 36 def valid_to_submit(*args) valid_to_draft(args) if errors.count == 0 valid_datacite? # test if the datacite update will be valid end errors.count == 0 end |