Module: Dor::Releaseable
- Extended by:
- ActiveSupport::Concern, Deprecation
- Included in:
- Collection, Item
- Defined in:
- lib/dor/models/concerns/releaseable.rb
Instance Method Summary collapse
-
#add_release_node(release, attrs = {}) ⇒ Nokogiri::XML::Element
Add a release node for the item Will use the current time if timestamp not supplied.
-
#add_release_nodes_and_start_releaseWF(release_tags) ⇒ Object
Add release tags to an item and initialize the item release workflow Each tag should be of the form {:tag => ‘Fitch : Batch2’, :what => ‘self’, :to => ‘Searchworks’, :who => ‘petucket’, :release => true}.
-
#released_for(skip_live_purl = false) ⇒ Hash{String => Boolean}
Called in Dor::UpdateMarcRecordService (in dor-services-app too) Determine projects in which an item is released.
- #releases ⇒ Object
-
#valid_release_attributes(tag, attrs = {}) ⇒ Boolean
Determine if the supplied tag is a valid release node that meets all requirements.
-
#valid_release_attributes_and_tag(tag, attrs = {}) ⇒ Boolean
Determine if the supplied tag is a valid release tag that meets all requirements.
Instance Method Details
#add_release_node(release, attrs = {}) ⇒ Nokogiri::XML::Element
Add a release node for the item Will use the current time if timestamp not supplied. You can supply a timestap for correcting history, etc if desired Timestamp will be calculated by the function
76 77 78 79 80 81 82 83 |
# File 'lib/dor/models/concerns/releaseable.rb', line 76 def add_release_node(release, attrs = {}) allowed_release_attributes = %i[what to who when] # any other release attributes sent in will be rejected and not stored = identityMetadata attrs.delete_if { |key, _value| !allowed_release_attributes.include?(key) } attrs[:when] = Time.now.utc.iso8601 if attrs[:when].nil? # add the timestamp valid_release_attributes(release, attrs) .add_value(:release, release.to_s, attrs) end |
#add_release_nodes_and_start_releaseWF(release_tags) ⇒ Object
Add release tags to an item and initialize the item release workflow Each tag should be of the form {:tag => ‘Fitch : Batch2’, :what => ‘self’, :to => ‘Searchworks’, :who => ‘petucket’, :release => true}
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dor/models/concerns/releaseable.rb', line 16 def add_release_nodes_and_start_releaseWF() = [] unless .is_a?(Array) # Add in each tag .each do |r_tag| add_release_node(r_tag[:release], r_tag) end # Save item to dor so the robots work with the latest data save create_workflow('releaseWF') end |
#released_for(skip_live_purl = false) ⇒ Hash{String => Boolean}
Called in Dor::UpdateMarcRecordService (in dor-services-app too) Determine projects in which an item is released
34 35 36 |
# File 'lib/dor/models/concerns/releaseable.rb', line 34 def released_for(skip_live_purl = false) releases.released_for(skip_live_purl: skip_live_purl) end |
#releases ⇒ Object
38 39 40 |
# File 'lib/dor/models/concerns/releaseable.rb', line 38 def releases @releases ||= ReleaseTagService.for(self) end |
#valid_release_attributes(tag, attrs = {}) ⇒ Boolean
Determine if the supplied tag is a valid release node that meets all requirements
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dor/models/concerns/releaseable.rb', line 92 def valid_release_attributes(tag, attrs = {}) raise ArgumentError, ':when is not iso8601' if attrs[:when].match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z').nil? %i[who to what].each do |check_attr| raise ArgumentError, "#{check_attr} not supplied as a String" if attrs[check_attr].class != String end raise ArgumentError, ':what must be self or collection' unless %w(self collection).include? attrs[:what] raise ArgumentError, 'the value set for this tag is not a boolean' unless [true, false].include? tag true end |
#valid_release_attributes_and_tag(tag, attrs = {}) ⇒ Boolean
Determine if the supplied tag is a valid release tag that meets all requirements
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dor/models/concerns/releaseable.rb', line 47 def valid_release_attributes_and_tag(tag, attrs = {}) raise ArgumentError, ':when is not iso8601' if attrs[:when].match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z').nil? %i[who to what].each do |check_attr| raise ArgumentError, "#{check_attr} not supplied as a String" if attrs[check_attr].class != String end what_correct = false %w(self collection).each do |allowed_what_value| what_correct = true if attrs[:what] == allowed_what_value end raise ArgumentError, ':what must be self or collection' unless what_correct raise ArgumentError, 'the value set for this tag is not a boolean' if !!tag != tag # rubocop:disable Style/DoubleNegation true end |