Sha256: e43c154d37a77073b08822e3c9522fdacdf0a5b6e6bd314a3b05d10276b4e9a1

Contents?: true

Size: 1.73 KB

Versions: 23

Compression:

Stored size: 1.73 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

    ##
    # @param [#state] resource
    # @return [Boolean]
    def self.inactive?(resource:)
      new(resource: resource).inactive?
    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

23 entries across 23 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/services/hyrax/resource_status.rb
hyrax-5.0.4 app/services/hyrax/resource_status.rb
hyrax-5.0.3 app/services/hyrax/resource_status.rb
hyrax-5.0.2 app/services/hyrax/resource_status.rb
hyrax-5.0.1 app/services/hyrax/resource_status.rb
hyrax-5.0.0 app/services/hyrax/resource_status.rb
hyrax-5.0.0.rc3 app/services/hyrax/resource_status.rb
hyrax-5.0.0.rc2 app/services/hyrax/resource_status.rb
hyrax-5.0.0.rc1 app/services/hyrax/resource_status.rb
hyrax-3.6.0 app/services/hyrax/resource_status.rb
hyrax-4.0.0 app/services/hyrax/resource_status.rb
hyrax-4.0.0.rc3 app/services/hyrax/resource_status.rb
hyrax-4.0.0.rc2 app/services/hyrax/resource_status.rb
hyrax-4.0.0.rc1 app/services/hyrax/resource_status.rb
hyrax-3.5.0 app/services/hyrax/resource_status.rb
hyrax-4.0.0.beta2 app/services/hyrax/resource_status.rb
hyrax-3.4.2 app/services/hyrax/resource_status.rb
hyrax-4.0.0.beta1 app/services/hyrax/resource_status.rb
hyrax-3.4.1 app/services/hyrax/resource_status.rb
hyrax-3.4.0 app/services/hyrax/resource_status.rb