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}.
-
#get_newest_release_tag(tags) ⇒ Hash
Take a hash of tags as obtained via Dor::Item.release_tags and returns the newest tag for each namespace.
-
#release_tags ⇒ Nokogiri::XML::NodeSet
Helper method to get the release tags as a nodeset.
-
#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
89 90 91 92 93 94 95 96 |
# File 'lib/dor/models/concerns/releaseable.rb', line 89 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 |
#get_newest_release_tag(tags) ⇒ Hash
Take a hash of tags as obtained via Dor::Item.release_tags and returns the newest tag for each namespace
46 47 48 |
# File 'lib/dor/models/concerns/releaseable.rb', line 46 def get_newest_release_tag() releases.newest_release_tag() end |
#release_tags ⇒ Nokogiri::XML::NodeSet
Helper method to get the release tags as a nodeset
40 |
# File 'lib/dor/models/concerns/releaseable.rb', line 40 delegate :release_tags, to: :releases |
#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
51 52 53 |
# File 'lib/dor/models/concerns/releaseable.rb', line 51 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
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/dor/models/concerns/releaseable.rb', line 105 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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dor/models/concerns/releaseable.rb', line 60 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 |