Skip to content
Browse files

Improved support for service specific default options.

  • Loading branch information...
1 parent 47dd1ac commit 0c1b47657cba9336ce3754ba7607f57a33d7aadd @jqr jqr committed Aug 29, 2008
Showing with 15 additions and 10 deletions.
  1. +7 −4 lib/snitch/service.rb
  2. +0 −1 lib/snitch/services/campfire.rb
  3. +2 −2 lib/snitch/services/email.rb
  4. +6 −3 lib/snitch/services/twitter.rb
View
11 lib/snitch/service.rb
@@ -1,19 +1,22 @@
class Snitch
class Service
- attr_reader :base, :attributes
+ attr_accessor :base, :attributes
def self.new_from_name(s, attributes)
"Snitch::Services::#{s.to_s.camelize}".constantize.new(attributes)
end
def initialize(attributes)
- defaults = { :message_length => :long }
- @attributes = defaults.merge(attributes || {})
+ self.attributes = default_options.merge(attributes || {})
+ end
+
+ def default_options
+ { :message_length => :long }
end
def method_missing(method, *args, &block)
if method.to_s =~ /=$/
- @attributes[method.to_s.chop] = args[0]
+ self.attributes[method.to_s.chop] = args[0]
else
attributes[method.to_s] || attributes[method] || super
end
View
1 lib/snitch/services/campfire.rb
@@ -3,7 +3,6 @@
class Snitch
module Services
class Campfire < Service
-
def connection
connection = ::Tinder::Campfire.new(subdomain)
connection.login(login, password)
View
4 lib/snitch/services/email.rb
@@ -6,8 +6,8 @@ class Snitch
module Services
class Email < Service
- def initialize(*args)
- super(*args)
+ def initialize(options)
+ super(options)
end
def tattle(message)
View
9 lib/snitch/services/twitter.rb
@@ -3,9 +3,12 @@
class Snitch
module Services
class Twitter < Service
-
- def initialize(attributes = {})
- super({ :message_length => :short }.merge(attributes))
+ def initialize(options = {})
+ super
+ end
+
+ def default_options
+ super.merge(:message_length => :short)
end
def connection

0 comments on commit 0c1b476

Please sign in to comment.
Something went wrong with that request. Please try again.