Class: Hyrax::ResourceStatus

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/resource_status.rb

Overview

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.

Examples:

status = ResourceStatus.new(resource: my_resource)
status.inactive? # => false

my_resource.state = ResourceStatus::INACTIVE
status = ResourceStatus.new(resource: my_resource)
status.inactive? # => true

See Also:

Constant Summary collapse

ACTIVE =
Vocab::FedoraResourceStatus.active.freeze
DELETED =
Vocab::FedoraResourceStatus.deleted.freeze
INACTIVE =
Vocab::FedoraResourceStatus.inactive.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ ResourceStatus

Returns a new instance of ResourceStatus.

Parameters:

  • resource (#state)


35
36
37
# File 'app/services/hyrax/resource_status.rb', line 35

def initialize(resource:)
  self.resource = resource
end

Instance Attribute Details

#resource#state

Returns:

  • (#state)


31
32
33
# File 'app/services/hyrax/resource_status.rb', line 31

def resource
  @resource
end

Class Method Details

.inactive?(resource:) ⇒ Boolean

Parameters:

  • resource (#state)

Returns:

  • (Boolean)


42
43
44
# File 'app/services/hyrax/resource_status.rb', line 42

def self.inactive?(resource:)
  new(resource: resource).inactive?
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)

    if the resource doesn’t have a state attribute



49
50
51
# File 'app/services/hyrax/resource_status.rb', line 49

def active?
  resource.state == ACTIVE
end

#deleted?Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)

    if the resource doesn’t have a state attribute



56
57
58
# File 'app/services/hyrax/resource_status.rb', line 56

def deleted?
  resource.state == DELETED
end

#inactive?Boolean

Returns:

  • (Boolean)

Raises:

  • (NoMethodError)

    if the resource doesn’t have a state attribute



63
64
65
# File 'app/services/hyrax/resource_status.rb', line 63

def inactive?
  resource.state == INACTIVE
end