Class: Snitch::Service
- Inherits:
-
Object
- Object
- Snitch::Service
- Defined in:
- lib/snitch/service.rb
Overview
Service is the base class for all services. All services should inherit from this class.
Direct Known Subclasses
Snitch::Services::Campfire, Snitch::Services::Email, Snitch::Services::Twitter
Class Attribute Summary collapse
-
.message_length ⇒ Object
Set up the class instance attribute for the commit message length.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Class Method Summary collapse
-
.new_from_name(s, attributes) ⇒ Object
Handy for creating a new instance of a service from the config file.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Service
constructor
A new instance of Service.
-
#method_missing(method, *args, &block) ⇒ Object
Uses method missing to return the value of a key in the attributes hash.
Constructor Details
#initialize(attributes = {}) ⇒ Service
Returns a new instance of Service.
24 25 26 |
# File 'lib/snitch/service.rb', line 24 def initialize(attributes = {}) @attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Uses method missing to return the value of a key in the attributes hash. Allows for doing this…
service.login
instead of this…
service.attributes[:login]
36 37 38 39 40 41 42 |
# File 'lib/snitch/service.rb', line 36 def method_missing(method, *args, &block) if method.to_s =~ /=$/ @attributes[method.to_s.chop] = args[0] else attributes[method.to_s] || attributes[method] || super end end |
Class Attribute Details
.message_length ⇒ Object
Set up the class instance attribute for the commit message length
9 10 11 |
# File 'lib/snitch/service.rb', line 9 def @message_length end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/snitch/service.rb', line 4 def attributes @attributes end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
4 5 6 |
# File 'lib/snitch/service.rb', line 4 def base @base end |
Class Method Details
.new_from_name(s, attributes) ⇒ Object
Handy for creating a new instance of a service from the config file. Simply pass in the service name and the attributes for the service and you get a new instance of the service.
Snitch::Service.new_from_name(:twitter, {:login => 'jnunemaker', :password => 'secret'})
# => #<Snitch::Services::Twitter:0x15a6508 @attributes={:login=>"jnunemaker", :password=>"secret"}>
18 19 20 21 |
# File 'lib/snitch/service.rb', line 18 def new_from_name(s, attributes) service = "Snitch::Services::#{s.to_s.camelize}".constantize service.new(attributes) end |