Module: Ethon::Easies::Options
- Included in:
- Ethon::Easy
- Defined in:
- lib/ethon/easies/options.rb
Overview
This module contains the logic and knowledge about the available options on easy.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#set_options ⇒ Object
Set specified options on easy handle.
-
#value_for(option) ⇒ Object
Return the value to set to easy handle.
Class Method Details
.included(base) ⇒ Object
:nodoc:
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ethon/easies/options.rb', line 9 def self.included(base) base.extend ClassMethods base.const_set(:AVAILABLE_OPTIONS, [ :dns_cache_timeout, :httppost, :put, :httpget, :nobody, :upload, :customrequest, :cainfo, :capath, :connecttimeout, :forbid_reuse, :followlocation, :httpauth, :infilesize, :interface, :maxredirs, :nosignal, :postfieldsize, :copypostfields, :proxy, :proxyauth, :proxyport, :proxytype, :timeout, :readdata, :sslcert, :ssl_verifypeer, :ssl_verifyhost, :sslcerttype, :sslkey, :sslkeytype, :sslversion, :url, :useragent, :userpwd, :verbose, :readfunction ]) base.send(:attr_accessor, *Ethon::Easy::AVAILABLE_OPTIONS) end |
Instance Method Details
#set_options ⇒ Object
Set specified options on easy handle.
76 77 78 79 80 |
# File 'lib/ethon/easies/options.rb', line 76 def self.class..each do |option| Curl.set_option(option, value_for(option), handle) end end |
#value_for(option) ⇒ Object
Return the value to set to easy handle. It is converted with the help of bool_options, enum_options and int_options.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ethon/easies/options.rb', line 89 def value_for(option) value = method(option).call return nil if value.nil? if self.class..include?(option) value ? 1 : 0 elsif self.class..key?(option) self.class.[option].to_h.fetch(value) do raise Errors::InvalidValue.new(option, value) end elsif self.class..include?(option) value.to_i elsif value.is_a?(::String) Util.escape_zero_byte(value) else value end end |