Class: Squawk
- Inherits:
-
Struct
- Object
- Struct
- Squawk
- Defined in:
- lib/squawk.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.register_event(event_name, message_or_method) ⇒ Object
Registers an update event.
- .test! ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#status ⇒ Object
Returns the value of attribute status
3 4 5 |
# File 'lib/squawk.rb', line 3 def status @status end |
Class Method Details
.register_event(event_name, message_or_method) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/squawk.rb', line 14 def register_event(event_name, ) @@events ||= [] event_name = event_name.to_sym return if @@events.include?(event_name) @@events << event_name.to_sym method_name = "#{event_name}!" (class << self; self; end).class_eval do # http://blog.jayfields.com/2008/02/ruby-dynamically-define-method.html # First, the easy case - string if .is_a?(String) define_method method_name do update end # Now, the harder case - lambda else define_method method_name do |*params| update(.call(*params)) end end end end |
.test! ⇒ Object
40 41 42 |
# File 'lib/squawk.rb', line 40 def test! update "The time is currently #{Time.now}" end |
Instance Method Details
#perform ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/squawk.rb', line 58 def perform Twitter.configure do |config| config.consumer_key = @@twitter_consumer_key config.consumer_secret = @@twitter_consumer_secret config.oauth_token = @@twitter_access_token config.oauth_token_secret = @@twitter_secret end Twitter::Client.new.update(status) end |