Class: Ridley::Connection
- Inherits:
-
Object
- Object
- Ridley::Connection
- Extended by:
- Forwardable
- Includes:
- DSL
- Defined in:
- lib/ridley/connection.rb
Overview
Constant Summary collapse
- REQUIRED_OPTIONS =
[ :server_url, :client_name, :client_key ]
- DEFAULT_THREAD_COUNT =
8
Instance Attribute Summary collapse
-
#client_key ⇒ Object
readonly
Returns the value of attribute client_key.
-
#client_name ⇒ Object
readonly
Returns the value of attribute client_name.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#thread_count ⇒ Object
Returns the value of attribute thread_count.
Class Method Summary collapse
Instance Method Summary collapse
- #api_type ⇒ Symbol
- #foss? ⇒ Boolean
- #hosted? ⇒ Boolean
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #sync(&block) ⇒ Object
Methods included from DSL
#client, #cookbook, #data_bag, #environment, #node, #role, #sandbox, #search, #search_indexes
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ridley/connection.rb', line 76 def initialize( = {}) self.class.() @client_name = .fetch(:client_name) @client_key = .fetch(:client_key) @organization = .fetch(:organization, nil) @thread_count = .fetch(:thread_count, DEFAULT_THREAD_COUNT) unless @client_key.present? && File.exist?(@client_key) raise Errors::ClientKeyFileNotFound, "client key not found at: '#{@client_key}'" end = .slice(:params, :headers, :request, :ssl, :proxy) uri_hash = Addressable::URI.parse([:server_url]).to_hash.slice(:scheme, :host, :port) unless uri_hash[:port] uri_hash[:port] = (uri_hash[:scheme] == "https" ? 443 : 80) end unless organization.nil? uri_hash[:path] = "/organizations/#{organization}" end server_uri = Addressable::URI.new(uri_hash) @conn = Faraday.new(server_uri, ) do |c| c.request :chef_auth, client_name, client_key c.response :chef_response c.response :json c.adapter Faraday.default_adapter end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
142 143 144 |
# File 'lib/ridley/connection.rb', line 142 def method_missing(method, *args, &block) @self_before_instance_eval.send(method, *args, &block) end |
Instance Attribute Details
#client_key ⇒ Object (readonly)
Returns the value of attribute client_key.
26 27 28 |
# File 'lib/ridley/connection.rb', line 26 def client_key @client_key end |
#client_name ⇒ Object (readonly)
Returns the value of attribute client_name.
25 26 27 |
# File 'lib/ridley/connection.rb', line 25 def client_name @client_name end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
27 28 29 |
# File 'lib/ridley/connection.rb', line 27 def organization @organization end |
#thread_count ⇒ Object
Returns the value of attribute thread_count.
29 30 31 |
# File 'lib/ridley/connection.rb', line 29 def thread_count @thread_count end |
Class Method Details
.sync(options, &block) ⇒ Object
5 6 7 |
# File 'lib/ridley/connection.rb', line 5 def sync(, &block) new().sync(&block) end |
.validate_options(options) ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/ridley/connection.rb', line 12 def () missing = (REQUIRED_OPTIONS - .keys) unless missing.empty? missing.collect! { |opt| "'#{opt}'" } raise ArgumentError, "Missing required option(s): #{missing.join(', ')}" end end |
Instance Method Details
#api_type ⇒ Symbol
119 120 121 |
# File 'lib/ridley/connection.rb', line 119 def api_type organization.nil? ? :foss : :hosted end |
#foss? ⇒ Boolean
129 130 131 |
# File 'lib/ridley/connection.rb', line 129 def foss? api_type == :foss end |
#hosted? ⇒ Boolean
124 125 126 |
# File 'lib/ridley/connection.rb', line 124 def hosted? api_type == :hosted end |
#sync(&block) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/ridley/connection.rb', line 110 def sync(&block) unless block raise Errors::InternalError, "A block must be given to synchronously process requests." end evaluate(&block) end |