Class: OdataDuty::Executor
- Inherits:
-
Object
- Object
- OdataDuty::Executor
- Defined in:
- lib/odata_duty/executor.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #execute ⇒ Object
-
#initialize(schema:, url:, context:, query_options:) ⇒ Executor
constructor
A new instance of Executor.
- #points ⇒ Object
- #prepare_builder(endpoint, context, query_options) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(schema:, url:, context:, query_options:) ⇒ Executor
Returns a new instance of Executor.
24 25 26 27 28 29 |
# File 'lib/odata_duty/executor.rb', line 24 def initialize(schema:, url:, context:, query_options:) @schema = schema @url = url @context = context @query_options = end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
22 23 24 |
# File 'lib/odata_duty/executor.rb', line 22 def context @context end |
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
22 23 24 |
# File 'lib/odata_duty/executor.rb', line 22 def @query_options end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
22 23 24 |
# File 'lib/odata_duty/executor.rb', line 22 def schema @schema end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
22 23 24 |
# File 'lib/odata_duty/executor.rb', line 22 def url @url end |
Class Method Details
.create ⇒ Object
10 11 12 |
# File 'lib/odata_duty/executor.rb', line 10 def self.create(**) new(**).create end |
.delete ⇒ Object
18 19 20 |
# File 'lib/odata_duty/executor.rb', line 18 def self.delete(**) new(**).delete end |
.execute ⇒ Object
6 7 8 |
# File 'lib/odata_duty/executor.rb', line 6 def self.execute(**) new(**).execute end |
.update ⇒ Object
14 15 16 |
# File 'lib/odata_duty/executor.rb', line 14 def self.update(**) new(**).update end |
Instance Method Details
#create ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/odata_duty/executor.rb', line 49 def create unless endpoint.supports_create? raise NoImplementationError, "create not implemented for #{endpoint.url}" end Oj.dump(endpoint .create(context: wrapped_context) .merge( '@odata.context': wrapped_context.od_full_url('$metadata', anchor: "#{endpoint.name}/$entity") ), mode: :compat) end |
#delete ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/odata_duty/executor.rb', line 78 def delete unless endpoint.supports_delete? raise NoImplementationError, "delete not implemented for #{endpoint.url}" end entity_id = extract_value_from_brackets(url) endpoint.delete(entity_id, context: wrapped_context) Oj.dump({ '@odata.context': wrapped_context.od_full_url('$metadata') }, mode: :compat) end |
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/odata_duty/executor.rb', line 33 def execute set_builder = prepare_builder(endpoint, wrapped_context, ) select = ['$select'] props = selected(endpoint.entity_type, select) if select apply_select(set_builder, props) if url.include?('(') individual(set_builder, endpoint, wrapped_context, props) elsif url.include?('/$count') apply_search(set_builder, ['$search']) set_builder.count else collection(set_builder, endpoint, wrapped_context, , props) end end |
#points ⇒ Object
31 |
# File 'lib/odata_duty/executor.rb', line 31 def points = schema.endpoints |
#prepare_builder(endpoint, context, query_options) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/odata_duty/executor.rb', line 88 def prepare_builder(endpoint, context, ) endpoint.new_entity_set(context: context).tap do |set_builder| filter = ['$filter'] apply_filter(endpoint, set_builder, filter) if .key?('$filter') end end |
#update ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/odata_duty/executor.rb', line 63 def update unless endpoint.supports_update? raise NoImplementationError, "update not implemented for #{endpoint.url}" end entity_id = extract_value_from_brackets(url) Oj.dump(endpoint .update(entity_id, context: wrapped_context) .merge( '@odata.context': wrapped_context.od_full_url('$metadata', anchor: "#{endpoint.name}/$entity") ), mode: :compat) end |