Class: Apiwork::API::RepresentationRegistry
- Inherits:
-
Object
- Object
- Apiwork::API::RepresentationRegistry
- Defined in:
- lib/apiwork/api/representation_registry.rb
Instance Method Summary collapse
- #clear! ⇒ Object
- #each(&block) ⇒ Object
- #filter_types ⇒ Object
- #filterable? ⇒ Boolean
- #include?(representation_class) ⇒ Boolean
-
#initialize ⇒ RepresentationRegistry
constructor
A new instance of RepresentationRegistry.
- #mark(representation_class, role) ⇒ Object
- #nested_writable?(representation_class) ⇒ Boolean
- #nullable_filter_types ⇒ Object
- #options_for(option, key = nil) ⇒ Object
- #register(representation_class) ⇒ Object
- #sortable? ⇒ Boolean
Constructor Details
#initialize ⇒ RepresentationRegistry
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_types ⇒ Object
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
53 54 55 |
# File 'lib/apiwork/api/representation_registry.rb', line 53 def filterable? filter_types.any? end |
#include?(representation_class) ⇒ 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
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_types ⇒ Object
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 (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
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 |