Module: FreshService::Configurable

Included in:
FreshService, Client
Defined in:
lib/fresh_service/configurable.rb

Overview

Configuration options for Client, defaulting to values in Default

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_endpointObject

Returns the value of attribute api_endpoint.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def api_endpoint
  @api_endpoint
end

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def api_key
  @api_key
end

#content_typeObject

Returns the value of attribute content_type.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def content_type
  @content_type
end

#envObject

Returns the value of attribute env.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def env
  @env
end

#organisationObject

Returns the value of attribute organisation.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def organisation
  @organisation
end

#user_agentObject

Returns the value of attribute user_agent.



7
8
9
# File 'lib/fresh_service/configurable.rb', line 7

def user_agent
  @user_agent
end

Class Method Details

.keysArray

List of configurable keys for FreshService::Client

Returns:

  • (Array)

    of option keys



13
14
15
16
17
18
19
20
21
22
# File 'lib/fresh_service/configurable.rb', line 13

def keys
  @keys ||= i[
    organisation
    env
    api_key
    content_type
    api_endpoint
    user_agent
  ]
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Set configuration options using a block

Yields:

  • (_self)

Yield Parameters:



26
27
28
# File 'lib/fresh_service/configurable.rb', line 26

def configure
  yield self
end

#reset!Object Also known as: setup

Reset configuration options to default values



31
32
33
34
35
36
# File 'lib/fresh_service/configurable.rb', line 31

def reset!
  FreshService::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", FreshService::Default.options[key])
  end
  self
end

#same_options?(opts) ⇒ Boolean

Compares client options to a Hash of requested options

Parameters:

  • opts (Hash)

    Options to compare with current client options

Returns:

  • (Boolean)


43
44
45
# File 'lib/fresh_service/configurable.rb', line 43

def same_options?(opts)
  opts.hash == options.hash
end