Class: OdataDuty::SchemaBuilder::Endpoint
- Inherits:
-
Object
- Object
- OdataDuty::SchemaBuilder::Endpoint
- Defined in:
- lib/odata_duty/schema_builder/endpoint.rb
Instance Attribute Summary collapse
-
#entity_set ⇒ Object
readonly
Returns the value of attribute entity_set.
Instance Method Summary collapse
- #collection(set_builder, context:, selected:) ⇒ Object
- #create(context:) ⇒ Object
- #delete(id, context:) ⇒ Object
- #entity_type ⇒ Object
- #individual(set_builder, id, context:, selected:) ⇒ Object
-
#initialize(entity_set) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #name ⇒ Object
- #new_entity_set(context:) ⇒ Object
- #supports_collection? ⇒ Boolean
- #supports_count? ⇒ Boolean
- #supports_create? ⇒ Boolean
- #supports_delete? ⇒ Boolean
- #supports_individual? ⇒ Boolean
- #supports_search? ⇒ Boolean
- #supports_update? ⇒ Boolean
- #update(id, context:) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(entity_set) ⇒ Endpoint
Returns a new instance of Endpoint.
6 7 8 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 6 def initialize(entity_set) @entity_set = entity_set end |
Instance Attribute Details
#entity_set ⇒ Object (readonly)
Returns the value of attribute entity_set.
4 5 6 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 4 def entity_set @entity_set end |
Instance Method Details
#collection(set_builder, context:, selected:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 19 def collection(set_builder, context:, selected:) unless set_builder.respond_to?(:collection) raise NoImplementationError, "collection not implemented for #{set_builder.class}" end values = set_builder.collection mapper = entity_type.mapper(context, selected: selected) # builder mapping never reads context; pass nil (accept equivalent mutant) values.map { |v| mapper.obj_to_hash(v, nil) } rescue StandardError => e extend_error(e, set_builder, :collection) end |
#create(context:) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 46 def create(context:) wrapper = CreateComplexTypeHashWrapper.new(context., entity_type, operation: :create, context: context) result = new_entity_set(context: context).create(wrapper) mapper = entity_type.mapper(context, selected: nil) mapper.obj_to_hash(result, nil) end |
#delete(id, context:) ⇒ Object
79 80 81 82 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 79 def delete(id, context:) result = new_entity_set(context: context).delete(converted_id(id)) raise ResourceNotFoundError, "No such entity #{id}" unless result end |
#entity_type ⇒ Object
17 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 17 def entity_type = entity_set.entity_type |
#individual(set_builder, id, context:, selected:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 33 def individual(set_builder, id, context:, selected:) unless set_builder.respond_to?(:individual) raise NoImplementationError, "individual not implemented for #{set_builder.class}" end result = set_builder.individual(converted_id(id)) raise ResourceNotFoundError, "No such entity #{id}" unless result entity_type.mapper(context, selected: selected).obj_to_hash(result, nil) rescue StandardError => e extend_error(e, set_builder, :individual) end |
#name ⇒ Object
10 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 10 def name = entity_set.name |
#new_entity_set(context:) ⇒ Object
13 14 15 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 13 def new_entity_set(context:) entity_set.resolver_class.new(context: context, init_args: entity_set.init_args) end |
#supports_collection? ⇒ Boolean
58 59 60 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 58 def supports_collection? entity_set.supports_collection? end |
#supports_count? ⇒ Boolean
66 67 68 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 66 def supports_count? entity_set.supports_count? end |
#supports_create? ⇒ Boolean
84 85 86 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 84 def supports_create? entity_set.supports_create? end |
#supports_delete? ⇒ Boolean
92 93 94 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 92 def supports_delete? entity_set.supports_delete? end |
#supports_individual? ⇒ Boolean
62 63 64 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 62 def supports_individual? entity_set.supports_individual? end |
#supports_search? ⇒ Boolean
54 55 56 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 54 def supports_search? entity_set.supports_search? end |
#supports_update? ⇒ Boolean
88 89 90 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 88 def supports_update? entity_set.supports_update? end |
#update(id, context:) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 70 def update(id, context:) wrapper = CreateComplexTypeHashWrapper.new(context., entity_type, operation: :update, context: context) result = new_entity_set(context: context).update(converted_id(id), wrapper) raise ResourceNotFoundError, "No such entity #{id}" unless result entity_type.mapper(context, selected: nil).obj_to_hash(result, nil) end |
#url ⇒ Object
11 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 11 def url = entity_set.url |