Class: Hydra::AccessControls::Embargo

Inherits:
ActiveFedora::Base
  • Object
show all
Defined in:
app/models/hydra/access_controls/embargo.rb

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/hydra/access_controls/embargo.rb', line 16

def active?
  (embargo_release_date.present? && Date.today < embargo_release_date)
end

#deactivate!Object

Deactivates the embargo and logs a message to the embargo_history property



21
22
23
24
25
26
27
28
29
# File 'app/models/hydra/access_controls/embargo.rb', line 21

def deactivate!
  return unless embargo_release_date
  embargo_state = active? ? "active" : "expired"
  embargo_record = embargo_history_message(embargo_state, Date.today, embargo_release_date, visibility_during_embargo, visibility_after_embargo)
  self.embargo_release_date = nil
  self.visibility_during_embargo = nil
  self.visibility_after_embargo = nil
  self.embargo_history += [embargo_record]
end

#embargo_release_date_with_casting=(date) ⇒ Object

Hack until ActiveFedora supports activeTriples 0.3.0 (then we can just use super)



10
11
12
13
# File 'app/models/hydra/access_controls/embargo.rb', line 10

def embargo_release_date_with_casting=(date)
  date = DateTime.parse(date) if date && date.kind_of?(String)
  self.embargo_release_date_without_casting = date
end

#to_hashObject



31
32
33
34
35
36
37
38
39
# File 'app/models/hydra/access_controls/embargo.rb', line 31

def to_hash
  {}.tap do |doc|
    date_field_name = Hydra.config.permissions.embargo.release_date.sub(/_dtsi/, '')
    Solrizer.insert_field(doc, date_field_name, embargo_release_date, :stored_sortable)
    doc[::Solrizer.solr_name("visibility_during_embargo", :symbol)] = visibility_during_embargo unless visibility_during_embargo.nil?
    doc[::Solrizer.solr_name("visibility_after_embargo", :symbol)] = visibility_after_embargo unless visibility_after_embargo.nil?
    doc[::Solrizer.solr_name("embargo_history", :symbol)] = embargo_history unless embargo_history.nil?
  end
end