Class: RequestItem
- Inherits:
-
Struct
- Object
- Struct
- RequestItem
- Defined in:
- public/app/models/request_item.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ RequestItem
constructor
A new instance of RequestItem.
-
#to_text(skip_empty = false) ⇒ Object
-
#to_text_array(skip_empty = false) ⇒ Object
-
#validate ⇒ Object
Constructor Details
#initialize(hash) ⇒ RequestItem
Returns a new instance of RequestItem.
35 36 37 38 39 |
# File 'public/app/models/request_item.rb', line 35 def initialize(hash) self.members.each do |sym| self[sym] = hash.fetch(sym, nil) end end |
Class Method Details
.allow_for_type(repository_code, record_type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'public/app/models/request_item.rb', line 10 def RequestItem.allow_for_type(repository_code, record_type) fallback = AppConfig[:pui_requests_permitted_for_types].include?(record_type) allowed_repo_types = AppConfig[:pui_repos].dig(repository_code.to_s.downcase, :requests_permitted_for_types) if repository_code if allowed_repo_types allowed_repo_types.include?(record_type) else fallback end end |
.allow_nontops(repo_code) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'public/app/models/request_item.rb', line 21 def RequestItem.allow_nontops(repo_code) allow = nil rep_allow = nil begin rep_allow = AppConfig[:pui_repos].dig(repo_code.downcase, :requests_permitted_for_containers_only) if repo_code allow = !rep_allow unless rep_allow.nil? rescue Exception => err raise err unless err..start_with?("No value set for config parameter") end allow = !AppConfig[:pui_requests_permitted_for_containers_only] if allow.nil? Rails.logger.debug("allow? #{ allow}") allow end |
Instance Method Details
#to_text(skip_empty = false) ⇒ Object
48 49 50 |
# File 'public/app/models/request_item.rb', line 48 def to_text(skip_empty = false) to_text_array(skip_empty).join("\n") end |
#to_text_array(skip_empty = false) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'public/app/models/request_item.rb', line 52 def to_text_array(skip_empty = false) arr = [] i(user_name user_email date note title identifier cite request_uri resource_name resource_id repo_name hierarchy restrict).each do |sym| arr.push("#{sym.to_s}: #{self[sym]}") unless skip_empty && self[sym].blank? end arr.push("machine: #{self[:machine].blank? ? '' : self[:machine].join(', ')}") if !self[:container].blank? && !self[:container].empty? self[:container].each_with_index do |v, i| # arr.push("#{:container.to_s}: #{v}") i(container top_container_url ).each do |sym| arr.push("#{sym.to_s}: #{defined?(self[sym][i]) ? self[sym][i] : ''}") end end elsif !skip_empty i(container top_container_url ).each {|sym| arr.push("#{sym.to_s}:") } end arr end |
#validate ⇒ Object
41 42 43 44 45 46 |
# File 'public/app/models/request_item.rb', line 41 def validate errs = [] errs.push(I18n.t('request.errors.name')) if self[:user_name].blank? errs.push(I18n.t('request.errors.email')) if self[:user_email].blank? || !self[:user_email].match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i) errs end |