Class: OdataDuty::ContextWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/odata_duty/context_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caller_context, base_url:, endpoint:, query_options:) ⇒ ContextWrapper

Returns a new instance of ContextWrapper.



8
9
10
11
12
13
# File 'lib/odata_duty/context_wrapper.rb', line 8

def initialize(caller_context, base_url:, endpoint:, query_options:)
  super(caller_context)
  @base_url = base_url.chomp('/')
  @endpoint = endpoint
  @query_options = query_options.to_h
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/odata_duty/context_wrapper.rb', line 6

def base_url
  @base_url
end

#caller_contextObject (readonly)

Returns the value of attribute caller_context.



6
7
8
# File 'lib/odata_duty/context_wrapper.rb', line 6

def caller_context
  @caller_context
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/odata_duty/context_wrapper.rb', line 6

def endpoint
  @endpoint
end

#query_optionsObject (readonly)

Returns the value of attribute query_options.



6
7
8
# File 'lib/odata_duty/context_wrapper.rb', line 6

def query_options
  @query_options
end

Instance Method Details

#currentObject



22
23
24
# File 'lib/odata_duty/context_wrapper.rb', line 22

def current
  @current ||= {}
end

#od_full_url(path, anchor: nil, **query_params) ⇒ Object



15
16
17
18
19
20
# File 'lib/odata_duty/context_wrapper.rb', line 15

def od_full_url(path, anchor: nil, **query_params)
  URI.parse([base_url, path].join('/')).tap do |uri|
    uri.query = URI.encode_www_form(query_params) if query_params.any?
    uri.fragment = anchor
  end.to_str
end