Class: Jarvis::Service
Direct Known Subclasses
Dice, Eightball, Fact, Giphy, IHeartQuotes, ImgFlip, NullService, TweetThat, Weather
Class Attribute Summary collapse
-
.interpreter_phrases ⇒ Object
Returns the value of attribute interpreter_phrases.
-
.invoker ⇒ Object
Returns the value of attribute invoker.
-
.pattern ⇒ Object
Returns the value of attribute pattern.
-
.required_environment_variables ⇒ Object
Returns the value of attribute required_environment_variables.
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
- .environment(*args) ⇒ Object
- .interpreter_pattern(pattern) ⇒ Object
-
.invoke_with(method_name) ⇒ Object
class MyService < Jarvis::Service invoke_with :post_tweet.
- .phrases(*args) ⇒ Object
Instance Method Summary collapse
-
#initialize(message) ⇒ Service
constructor
A new instance of Service.
- #method_missing(name, *args, &blk) ⇒ Object
- #run ⇒ Object
- #validate_environment ⇒ Object
Constructor Details
permalink #initialize(message) ⇒ Service
Returns a new instance of Service.
7 8 9 10 |
# File 'lib/jarvis/service.rb', line 7 def initialize() @message = @response = "" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(name, *args, &blk) ⇒ Object
[View source]
12 13 14 |
# File 'lib/jarvis/service.rb', line 12 def method_missing(name, *args, &blk) .public_send(name, *args, &blk) end |
Class Attribute Details
permalink .interpreter_phrases ⇒ Object
Returns the value of attribute interpreter_phrases.
28 29 30 |
# File 'lib/jarvis/service.rb', line 28 def interpreter_phrases @interpreter_phrases end |
permalink .invoker ⇒ Object
Returns the value of attribute invoker.
28 29 30 |
# File 'lib/jarvis/service.rb', line 28 def invoker @invoker end |
permalink .pattern ⇒ Object
Returns the value of attribute pattern.
28 29 30 |
# File 'lib/jarvis/service.rb', line 28 def pattern @pattern end |
permalink .required_environment_variables ⇒ Object
Returns the value of attribute required_environment_variables.
28 29 30 |
# File 'lib/jarvis/service.rb', line 28 def required_environment_variables @required_environment_variables end |
Instance Attribute Details
permalink #message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/jarvis/service.rb', line 6 def @message end |
permalink #response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/jarvis/service.rb', line 6 def response @response end |
Class Method Details
permalink .environment(*args) ⇒ Object
[View source]
40 41 42 43 44 45 46 47 48 |
# File 'lib/jarvis/service.rb', line 40 def self.environment(*args) args.each do |sym| str = sym.to_s.upcase send :define_method, sym do ENV[str] || ENV[str.downcase] end required_environment_variables << str end end |
permalink .interpreter_pattern(pattern) ⇒ Object
[View source]
51 52 53 |
# File 'lib/jarvis/service.rb', line 51 def self.interpreter_pattern(pattern) @pattern = pattern end |
permalink .invoke_with(method_name) ⇒ Object
class MyService < Jarvis::Service
invoke_with :post_tweet
end
63 64 65 66 67 68 69 70 |
# File 'lib/jarvis/service.rb', line 63 def self.invoke_with(method_name) send :define_method, :invoke do run_hook :before_invoke self.response = send method_name run_hook :after_invoke self.response end end |
permalink .phrases(*args) ⇒ Object
[View source]
31 32 33 34 |
# File 'lib/jarvis/service.rb', line 31 def self.phrases(*args) @interpreter_phrases = args reset_interpreter_pattern end |
Instance Method Details
permalink #validate_environment ⇒ Object
[View source]
20 21 22 23 24 |
# File 'lib/jarvis/service.rb', line 20 def validate_environment self.class.required_environment_variables.each do |v| raise UnfitEnvironmentException unless (ENV[v] || ENV[v.downcase]) end end |