Class: Hyrax::ChildTypes

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
app/services/hyrax/child_types.rb

Overview

A list of child work types a user may choose to attach for a given work type

These lists are used when users select among work types to attach to an existing work, e.g. from Actions available on the show view.

Examples:

child_types = Hyrax::ChildTypes.for(parent: MyWorkType)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ ChildTypes

Returns a new instance of ChildTypes.

Parameters:

  • types (Array<Class>)


36
37
38
# File 'app/services/hyrax/child_types.rb', line 36

def initialize(types)
  @types = types.to_a
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



22
23
24
# File 'app/services/hyrax/child_types.rb', line 22

def types
  @types
end

Class Method Details

.for(parent:) ⇒ Enumerable<Class>

Returns a list of classes that are valid as child types for ‘parent`.

Returns:

  • (Enumerable<Class>)

    a list of classes that are valid as child types for ‘parent`



27
28
29
30
31
32
# File 'app/services/hyrax/child_types.rb', line 27

def self.for(parent:)
  return new(parent.valid_child_concerns) if
    parent.respond_to?(:valid_child_concerns)

  new([parent])
end