Class: Hydra::AccessControls::Lease

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

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/models/hydra/access_controls/lease.rb', line 15

def active?
  lease_expiration_date.present? && Date.today < lease_expiration_date
end

#deactivate!Object



19
20
21
22
23
24
25
26
27
# File 'app/models/hydra/access_controls/lease.rb', line 19

def deactivate!
  return unless lease_expiration_date
  lease_state = active? ? "active" : "expired"
  lease_record = lease_history_message(lease_state, Date.today, lease_expiration_date, visibility_during_lease, visibility_after_lease)
  self.lease_expiration_date = nil
  self.visibility_during_lease = nil
  self.visibility_after_lease = nil
  self.lease_history += [lease_record]
end

#lease_expiration_date_with_casting=(date) ⇒ Object

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



9
10
11
12
# File 'app/models/hydra/access_controls/lease.rb', line 9

def lease_expiration_date_with_casting=(date)
  date = DateTime.parse(date) if date && date.kind_of?(String)
  self.lease_expiration_date_without_casting = date
end

#to_hashObject



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

def to_hash
  {}.tap do |doc|
    date_field_name = Hydra.config.permissions.lease.expiration_date.sub(/_dtsi/, '')
    Solrizer.insert_field(doc, date_field_name, lease_expiration_date, :stored_sortable)

    doc[::Solrizer.solr_name("visibility_during_lease", :symbol)] = visibility_during_lease unless visibility_during_lease.nil?
    doc[::Solrizer.solr_name("visibility_after_lease", :symbol)] = visibility_after_lease unless visibility_after_lease.nil?
    doc[::Solrizer.solr_name("lease_history", :symbol)] = lease_history unless lease_history.nil?
  end
end