Class: PostCommit::Hooks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/post_commit/hooks/base.rb

Direct Known Subclasses

Basecamp, Campfire, FriendFeed, LightHouse, Twitter, URL

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize

Returns a new instance of Base



19
20
21
22
# File 'lib/post_commit/hooks/base.rb', line 19

def initialize
  @credentials = {}
  @options = {}
end

Instance Attribute Details

- (Object) credentials (readonly)

Hold the authorization options.



5
6
7
# File 'lib/post_commit/hooks/base.rb', line 5

def credentials
  @credentials
end

- (Object) options (readonly)

Hold options defined throught the PostCommit::Hooks::Base#set method



17
18
19
# File 'lib/post_commit/hooks/base.rb', line 17

def options
  @options
end

- (Object) request (readonly)

Hold the latest request object



11
12
13
# File 'lib/post_commit/hooks/base.rb', line 11

def request
  @request
end

- (Object) response (readonly)

Hold the latest response



8
9
10
# File 'lib/post_commit/hooks/base.rb', line 8

def response
  @response
end

- (Object) uri (readonly)

Hold the latest uri object



14
15
16
# File 'lib/post_commit/hooks/base.rb', line 14

def uri
  @uri
end

Class Method Details

+ (Object) inherited(base)



24
25
26
# File 'lib/post_commit/hooks/base.rb', line 24

def self.inherited(base)
  PostCommit::Hooks.register base.name.split("::").last.downcase.to_sym, base
end

Instance Method Details

- (Object) authorize(options = {})

Set up the authorization for the current notifier. Each notifier can have its own authorization options.



30
31
32
# File 'lib/post_commit/hooks/base.rb', line 30

def authorize(options = {})
  @credentials = options
end

- (Object) convert_to_params(hash)

:nodoc:



65
66
67
# File 'lib/post_commit/hooks/base.rb', line 65

def convert_to_params(hash) # :nodoc:
  hash
end

- (Object) convert_to_xml(hash)

:nodoc:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/post_commit/hooks/base.rb', line 46

def convert_to_xml(hash) # :nodoc:
  xml_node = Proc.new do |name, value, buffer|
    buffer ||= ""

    if value.kind_of?(Hash)
      buffer << "<#{name}>"
      value.each {|n, v| buffer << xml_node[n, v] }
      buffer << "</#{name}>"
    else
      buffer << "<#{name}><![CDATA[#{value}]]></#{name}>"
    end

    buffer
  end

  root = hash.keys.first
  xml_node[root, hash[root]]
end

- (Object) post(options = {})

:nodoc:



42
43
44
# File 'lib/post_commit/hooks/base.rb', line 42

def post(options = {}) # :nodoc:
  raise PostCommit::AbstractMethodError
end

- (Object) set(name, value)

Set an option for the current hook. The available options may vary from hook to hook and may not be available at all.

set :data_type, :json


38
39
40
# File 'lib/post_commit/hooks/base.rb', line 38

def set(name, value)
  @options[name.to_sym] = value
end