Class: MoexRuby::Configuration
- Inherits:
-
Object
- Object
- MoexRuby::Configuration
- Defined in:
- lib/moex_ruby/configuration.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
'https://iss.moex.com'- DEFAULT_TIMEOUT =
30- OPEN_TIMEOUT_RATIO =
0.33
Instance Attribute Summary collapse
-
#auto_paginate ⇒ Object
Returns the value of attribute auto_paginate.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#middleware_stack ⇒ Object
readonly
Returns the value of attribute middleware_stack.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #adapter(adapter_name = nil) ⇒ Object
- #adapter_name ⇒ Object
- #apply_to_faraday(faraday) ⇒ Object
- #calculated_open_timeout ⇒ Object
-
#customize(&block) ⇒ Object
Для продвинутой кастомизации через блок.
- #has_custom_middleware? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #request(middleware, *args, **options) ⇒ Object
- #response(middleware, *args, **options) ⇒ Object
- #use(middleware, *args, **options, &block) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
12 13 14 15 16 17 18 19 |
# File 'lib/moex_ruby/configuration.rb', line 12 def initialize @base_url = DEFAULT_BASE_URL @timeout = DEFAULT_TIMEOUT @open_timeout = nil @auto_paginate = false @middleware_stack = [] @custom_block = nil end |
Instance Attribute Details
#auto_paginate ⇒ Object
Returns the value of attribute auto_paginate.
9 10 11 |
# File 'lib/moex_ruby/configuration.rb', line 9 def auto_paginate @auto_paginate end |
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/moex_ruby/configuration.rb', line 9 def base_url @base_url end |
#middleware_stack ⇒ Object (readonly)
Returns the value of attribute middleware_stack.
10 11 12 |
# File 'lib/moex_ruby/configuration.rb', line 10 def middleware_stack @middleware_stack end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
9 10 11 |
# File 'lib/moex_ruby/configuration.rb', line 9 def open_timeout @open_timeout end |
#timeout ⇒ Object
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/moex_ruby/configuration.rb', line 9 def timeout @timeout end |
Instance Method Details
#adapter(adapter_name = nil) ⇒ Object
29 30 31 |
# File 'lib/moex_ruby/configuration.rb', line 29 def adapter(adapter_name = nil) @adapter = adapter_name end |
#adapter_name ⇒ Object
48 49 50 |
# File 'lib/moex_ruby/configuration.rb', line 48 def adapter_name @adapter || :net_http end |
#apply_to_faraday(faraday) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/moex_ruby/configuration.rb', line 52 def apply_to_faraday(faraday) # Применяем middleware из стека @middleware_stack.each do |config| case config[:type] when :request faraday.request config[:name], *config[:args], **config[:options] when :response faraday.response config[:name], *config[:args], **config[:options] when :use faraday.use config[:middleware], *config[:args], &config[:block] end end # Применяем кастомный блок если есть @custom_block&.call(faraday) end |
#calculated_open_timeout ⇒ Object
44 45 46 |
# File 'lib/moex_ruby/configuration.rb', line 44 def calculated_open_timeout @open_timeout || (@timeout * OPEN_TIMEOUT_RATIO).ceil end |
#customize(&block) ⇒ Object
Для продвинутой кастомизации через блок
40 41 42 |
# File 'lib/moex_ruby/configuration.rb', line 40 def customize(&block) @custom_block = block end |
#has_custom_middleware? ⇒ Boolean
69 70 71 |
# File 'lib/moex_ruby/configuration.rb', line 69 def has_custom_middleware? @middleware_stack.any? || !@custom_block.nil? end |
#request(middleware, *args, **options) ⇒ Object
21 22 23 |
# File 'lib/moex_ruby/configuration.rb', line 21 def request(middleware, *args, **) @middleware_stack << { type: :request, name: middleware, args: args, options: } end |
#response(middleware, *args, **options) ⇒ Object
25 26 27 |
# File 'lib/moex_ruby/configuration.rb', line 25 def response(middleware, *args, **) @middleware_stack << { type: :response, name: middleware, args: args, options: } end |
#use(middleware, *args, **options, &block) ⇒ Object
33 34 35 36 37 |
# File 'lib/moex_ruby/configuration.rb', line 33 def use(middleware, *args, **, &block) combined_args = args combined_args << unless .empty? @middleware_stack << { type: :use, middleware: middleware, args: combined_args, block: block } end |