Class: Blacksmith::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/blacksmith/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_tokenObject

Returns the value of attribute api_token.



5
6
7
# File 'lib/blacksmith/config.rb', line 5

def api_token
  @api_token
end

.patternsObject

Returns the value of attribute patterns.



5
6
7
# File 'lib/blacksmith/config.rb', line 5

def patterns
  @patterns
end

.roomObject

Returns the value of attribute room.



5
6
7
# File 'lib/blacksmith/config.rb', line 5

def room
  @room
end

.server_urlObject

Returns the value of attribute server_url.



5
6
7
# File 'lib/blacksmith/config.rb', line 5

def server_url
  @server_url
end

.titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/blacksmith/config.rb', line 5

def title
  @title
end

Class Method Details

.connectionObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/blacksmith/config.rb', line 7

def connection
  return @client if @client

  ["room", "api_token"].each do |attr|
    if eval(attr).nil?
      raise ConfigError, "Missing configuration: #{attr}. Check README to setup." 
    end
  end

  @client = if server_url
              HipChat::Client.new(api_token, server_url: server_url)
            else
              HipChat::Client.new(api_token)
            end
end

.draw(&block) ⇒ Object



27
28
29
# File 'lib/blacksmith/config.rb', line 27

def draw(&block)
  class_eval(&block)
end

.establish_connection!Object



23
24
25
# File 'lib/blacksmith/config.rb', line 23

def establish_connection!
  connection
end

.map(pattern = nil, options = {}) ⇒ Object

Raises:



31
32
33
34
35
36
37
38
39
# File 'lib/blacksmith/config.rb', line 31

def map(pattern = nil, options = {})
  self.patterns ||= {}

  raise MappingError, "Pattern can only be a Regexp" unless pattern.is_a? Regexp
  raise MappingError, "Pattern cannot be blank" if pattern == //
  raise MappingError, "Missing target in mapping. Use: to: 'image_url'"  if options.is_a?(Hash).! || options[:to].nil?

  self.patterns[pattern] = options[:to]
end