Class: GoogleApi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/google_api/configuration.rb

Constant Summary collapse

DEFAULT =
{
  client_id: nil,
  client_secret: nil,
  client_developer_email: nil,
  client_cert_file: nil,
  key_secret: 'notasecret',
  redirect_uri: nil,
}

Instance Method Summary collapse

Constructor Details

#initialize(config, use_default = true) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/google_api/configuration.rb', line 13

def initialize(config, use_default = true)

  if use_default
    config = DEFAULT.merge(config)
  end

  config.each do |key, value|
    eval <<-METHOD
      def #{key}(value = nil, &block)
        if block_given?
          @#{key}.instance_eval(&block)
        end

        if value.nil?
          return @#{key}
        end

        self.#{key} = value
      end

      def #{key}=(value)
        @#{key} = value
      end
    METHOD

    self.send("#{key}=", value)
  end
end

Instance Method Details

#configure(&block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/google_api/configuration.rb', line 42

def configure(&block)
  if block_given?
    yield self
  end

  self
end