Class: SteamMist::PseudoInterface
- Inherits:
-
Object
- Object
- SteamMist::PseudoInterface
- Defined in:
- lib/steam_mist/pseudo_interface.rb,
lib/steam_mist/pseudo_interface/pseudo_method.rb
Overview
This basically represents an interface for the Web API.
Defined Under Namespace
Classes: PseudoMethod
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The interface’s name that this is representing.
-
#session ⇒ Session
readonly
The session that the interface is running under.
Instance Method Summary collapse
-
#api_name ⇒ String
Turns the interface name into the corresponding api name.
-
#get_method(method_name, version = 1) ⇒ PseudoMethod
Grab a method from this interface.
-
#initialize(session, interface_name) ⇒ PseudoInterface
constructor
Initialize the pseudointerface with the interface name.
-
#inspect ⇒ String
Pretty inspection.
-
#method_missing(method, *args) ⇒ Object
Some #method_missing magic.
Constructor Details
#initialize(session, interface_name) ⇒ PseudoInterface
Initialize the pseudointerface with the interface name. See #api_name for information about how this is handled.
24 25 26 27 |
# File 'lib/steam_mist/pseudo_interface.rb', line 24 def initialize(session, interface_name) @name = interface_name @session = session end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Some #method_missing magic. Sorry @charliesome!
62 63 64 65 |
# File 'lib/steam_mist/pseudo_interface.rb', line 62 def method_missing(method, *args) super if args.length > 1 or block_given? get_method method, *args end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
The interface’s name that this is representing. This should be in underscore form.
11 12 13 |
# File 'lib/steam_mist/pseudo_interface.rb', line 11 def name @name end |
#session ⇒ Session (readonly)
The session that the interface is running under. This is used mainly for the connector.
17 18 19 |
# File 'lib/steam_mist/pseudo_interface.rb', line 17 def session @session end |
Instance Method Details
#api_name ⇒ String
Turns the interface name into the corresponding api name. If the interface starts with an ‘I`, it makes no modifications to it (other than turning it into a string). If it doesn’t, however, it turns it from snake case to camel case (i.e. ‘some_interface` to `SomeInterface`). It then adds an `I` to the front of it.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/steam_mist/pseudo_interface.rb', line 45 def api_name @_api_name ||= begin str = name.to_s if str[0] == "I" str else str.gsub!(/_([a-z])/) { |m| m[1].upcase } str[0] = str[0].upcase "I#{str}" end end end |
#get_method(method_name, version = 1) ⇒ PseudoMethod
Grab a method from this interface.
34 35 36 |
# File 'lib/steam_mist/pseudo_interface.rb', line 34 def get_method(method_name, version=1) PseudoMethod.new(self, method_name, version) end |
#inspect ⇒ String
Pretty inspection.
70 71 72 |
# File 'lib/steam_mist/pseudo_interface.rb', line 70 def inspect "#<SteamMist::PseudoInterface #{name}>" end |