Sha256: 08f812df1e7dde64d1162376172041abb1258276739f029e78f16381c16efc36

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # Implements the Fedora objState ontology against the given resource.
  #
  # Use the provided constants as values for `#status` to set state. The
  # boolean methods provide easy checking of state.
  #
  # We assume that no-state, means none of the three object statuses are
  # satisfied. Errors are raised if the `#state` attribute isn't defined.
  #
  # @see http://fedora.info/definitions/1/0/access/ObjState
  #
  # @example
  #   status = ResourceStatus.new(resource: my_resource)
  #   status.inactive? # => false
  #
  #   my_resource.state = ResourceStatus::INACTIVE
  #   status = ResourceStatus.new(resource: my_resource)
  #   status.inactive? # => true
  #
  class ResourceStatus
    ACTIVE   = Vocab::FedoraResourceStatus.active.freeze
    DELETED  = Vocab::FedoraResourceStatus.deleted.freeze
    INACTIVE = Vocab::FedoraResourceStatus.inactive.freeze

    ##
    # @!attribute [rw] resource
    #   @return [#state]
    attr_accessor :resource

    ##
    # @param [#state] resource
    def initialize(resource:)
      self.resource = resource
    end

    ##
    # @return [Boolean]
    # @raise [NoMethodError] if the resource doesn't have a state attribute
    def active?
      resource.state == ACTIVE
    end

    ##
    # @return [Boolean]
    # @raise [NoMethodError] if the resource doesn't have a state attribute
    def deleted?
      resource.state == DELETED
    end

    ##
    # @return [Boolean]
    # @raise [NoMethodError] if the resource doesn't have a state attribute
    def inactive?
      resource.state == INACTIVE
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-3.0.2 app/services/hyrax/resource_status.rb
hyrax-3.0.1 app/services/hyrax/resource_status.rb
hyrax-3.0.0 app/services/hyrax/resource_status.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/resource_status.rb
hyrax-3.0.0.pre.rc3 app/services/hyrax/resource_status.rb
hyrax-3.0.0.pre.rc2 app/services/hyrax/resource_status.rb