Class: Apiwork::API::RepresentationRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/api/representation_registry.rb

Instance Method Summary collapse

Constructor Details

#initializeRepresentationRegistry

Returns a new instance of RepresentationRegistry.



6
7
8
9
# File 'lib/apiwork/api/representation_registry.rb', line 6

def initialize
  @store = Set.new
  @roles = Hash.new { |hash, key| hash[key] = Set.new }
end

Instance Method Details

#clear!Object



31
32
33
34
# File 'lib/apiwork/api/representation_registry.rb', line 31

def clear!
  @store.clear
  @roles.clear
end

#each(&block) ⇒ Object



23
24
25
# File 'lib/apiwork/api/representation_registry.rb', line 23

def each(&block)
  @store.each(&block)
end

#filter_typesObject



36
37
38
# File 'lib/apiwork/api/representation_registry.rb', line 36

def filter_types
  @filter_types ||= extract_filter_types(nullable: false)
end

#filterable?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/apiwork/api/representation_registry.rb', line 53

def filterable?
  filter_types.any?
end

#include?(representation_class) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/apiwork/api/representation_registry.rb', line 27

def include?(representation_class)
  @store.include?(representation_class)
end

#mark(representation_class, role) ⇒ Object



15
16
17
# File 'lib/apiwork/api/representation_registry.rb', line 15

def mark(representation_class, role)
  @roles[representation_class].add(role)
end

#nested_writable?(representation_class) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/apiwork/api/representation_registry.rb', line 19

def nested_writable?(representation_class)
  @roles[representation_class].include?(:nested_writable)
end

#nullable_filter_typesObject



40
41
42
# File 'lib/apiwork/api/representation_registry.rb', line 40

def nullable_filter_types
  @nullable_filter_types ||= extract_filter_types(nullable: true)
end

#options_for(option, key = nil) ⇒ Object



57
58
59
# File 'lib/apiwork/api/representation_registry.rb', line 57

def options_for(option, key = nil)
  @store.filter_map { |representation| representation.adapter_config.dig(option, key) }.to_set
end

#register(representation_class) ⇒ Object



11
12
13
# File 'lib/apiwork/api/representation_registry.rb', line 11

def register(representation_class)
  @store.add(representation_class)
end

#sortable?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/apiwork/api/representation_registry.rb', line 44

def sortable?
  return @sortable if defined?(@sortable)

  @sortable = @store.any? do |representation|
    representation.attributes.values.any?(&:sortable?) ||
      representation.associations.values.any?(&:sortable?)
  end
end