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
- #description ⇒ 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
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 20 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
47 48 49 50 51 52 53 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 47 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
80 81 82 83 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 80 def delete(id, context:) result = new_entity_set(context: context).delete(converted_id(id)) raise ResourceNotFoundError, "No such entity #{id}" unless result end |
#description ⇒ Object
12 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 12 def description = entity_set.description |
#entity_type ⇒ Object
18 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 18 def entity_type = entity_set.entity_type |
#individual(set_builder, id, context:, selected:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 34 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
14 15 16 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 14 def new_entity_set(context:) entity_set.resolver_class.new(context: context, init_args: entity_set.init_args) end |
#supports_collection? ⇒ Boolean
59 60 61 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 59 def supports_collection? entity_set.supports_collection? end |
#supports_count? ⇒ Boolean
67 68 69 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 67 def supports_count? entity_set.supports_count? end |
#supports_create? ⇒ Boolean
85 86 87 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 85 def supports_create? entity_set.supports_create? end |
#supports_delete? ⇒ Boolean
93 94 95 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 93 def supports_delete? entity_set.supports_delete? end |
#supports_individual? ⇒ Boolean
63 64 65 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 63 def supports_individual? entity_set.supports_individual? end |
#supports_search? ⇒ Boolean
55 56 57 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 55 def supports_search? entity_set.supports_search? end |
#supports_update? ⇒ Boolean
89 90 91 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 89 def supports_update? entity_set.supports_update? end |
#update(id, context:) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/odata_duty/schema_builder/endpoint.rb', line 71 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 |