Module: PeepingTom::DSL
- Defined in:
- lib/peeping_tom/dsl.rb
Instance Method Summary collapse
- #channel(type, *opts) ⇒ Object
- #channels ⇒ Object
- #error! ⇒ Object
- #errors ⇒ Object
- #group(name, &block) ⇒ Object
- #no_errors ⇒ Object
- #ping(site, method = :head) ⇒ Object
- #site(name, site, opts = {}) ⇒ Object
- #watch(name) ⇒ Object
Instance Method Details
#channel(type, *opts) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/peeping_tom/dsl.rb', line 61 def channel(type, *opts) if type == :irc require File.join(File.dirname(__FILE__), "notifier", "irc") channel = PeepingTom::Notifier::IRC.new(*opts) elsif type == :email require File.join(File.dirname(__FILE__), "notifier", "email") channel = PeepingTom::Notifier::Email.new(*opts) else raise ArgumentError, "unknown channel type: #{type}" end @channels ||= [] @channels << channel end |
#channels ⇒ Object
24 25 26 |
# File 'lib/peeping_tom/dsl.rb', line 24 def channels @channels end |
#error! ⇒ Object
49 50 51 52 53 |
# File 'lib/peeping_tom/dsl.rb', line 49 def error! @error = true @errors = true return false end |
#errors ⇒ Object
39 40 41 42 |
# File 'lib/peeping_tom/dsl.rb', line 39 def errors return unless @errors yield end |
#group(name, &block) ⇒ Object
55 56 57 58 59 |
# File 'lib/peeping_tom/dsl.rb', line 55 def group(name, &block) PeepingTom.set_peeper(name) yield PeepingTom.reset_peeper end |
#no_errors ⇒ Object
44 45 46 47 |
# File 'lib/peeping_tom/dsl.rb', line 44 def no_errors return if @errors yield end |
#ping(site, method = :head) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/peeping_tom/dsl.rb', line 7 def ping(site, method = :head) method = method.to_s.downcase raise ArgumentError, "only accepts head or get" unless ['head', 'get'].include?(method) Timeout::timeout(site.timeout) do url = URI.parse(site.url) res = Net::HTTP.start(url.host, url.port) do |http| file = "/" + url.to_s.sub(/http:\/\/.*?\//, '') http.send(method, file) end return res.code.to_i >= 200 && res.code.to_i < 400 end return error! rescue Timeout::Error, Errno::ECONNREFUSED, SocketError return error! end |
#site(name, site, opts = {}) ⇒ Object
75 76 77 |
# File 'lib/peeping_tom/dsl.rb', line 75 def site(name, site, opts = {}) PeepingTom.peeper.register(name, site, opts) end |