Class: Mikrotik::Command
- Inherits:
-
Object
- Object
- Mikrotik::Command
- Defined in:
- lib/mikrotik/command.rb
Overview
Class encapsulating a API command to be executed on the device
Instance Attribute Summary (collapse)
-
- (String) command
readonly
Path to the command.
-
- (Hash) options
readonly
All option name/value pairs set on the command.
-
- (Array<Mikrotik::Protocol::Sentence>) replies
readonly
All sentences sent in response to this command so far.
Instance Method Summary (collapse)
-
- (Object) done {|replies| ... }
Fired when the command completes.
-
- (String) encoded
Encodes the command for transmission.
-
- (Command) initialize(*command_path)
constructor
Creates a new command object.
-
- (Object) reply {|reply| ... }
Fired on each reply received from the command.
-
- (self) returning(*properties)
Specifies what properties should be returned by the device in response to this command.
-
- (Object) trap {|error_message| ... }
Fired when an error response is received from the command.
-
- (Object) where(conditions = {})
Adds querying conditions to the command.
-
- (Object) with(options = {})
Adds property names and values to the command.
Constructor Details
- (Command) initialize(*command_path)
Creates a new command object
31 32 33 34 35 36 |
# File 'lib/mikrotik/command.rb', line 31 def initialize(*command_path) @command = command_path.collect { |part| "#{part}".gsub('_', '-') }.join('/') @command = "/#{@command}" unless @command.start_with?('/') @options = {} @replies = [] end |
Instance Attribute Details
- (String) command (readonly)
Path to the command
27 28 29 |
# File 'lib/mikrotik/command.rb', line 27 def command @command end |
- (Hash) options (readonly)
All option name/value pairs set on the command
24 25 26 |
# File 'lib/mikrotik/command.rb', line 24 def @options end |
- (Array<Mikrotik::Protocol::Sentence>) replies (readonly)
All sentences sent in response to this command so far
21 22 23 |
# File 'lib/mikrotik/command.rb', line 21 def replies @replies end |
Instance Method Details
- (Object) done {|replies| ... }
Fired when the command completes
8 |
# File 'lib/mikrotik/command.rb', line 8 has_events :done |
- (String) encoded
Encodes the command for transmission
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mikrotik/command.rb', line 70 def encoded @command.to_mikrotik_word + @options.collect { |key, value| case value.class.name when 'Array' [key, value.collect { |item| "#{item}" }.join(',')].join '=' else "#{key}=#{value}" end }.map { |option| option.to_mikrotik_word }.join + 0x00.chr end |
- (Object) reply {|reply| ... }
Fired on each reply received from the command
13 |
# File 'lib/mikrotik/command.rb', line 13 has_event :reply |
- (self) returning(*properties)
Specifies what properties should be returned by the device in response to this command
60 61 62 63 64 65 66 |
# File 'lib/mikrotik/command.rb', line 60 def returning(*properties) @options['=.proplist'] ||= [] properties.each do |property| @options['=.proplist'] << "#{property}" end self end |
- (Object) trap {|error_message| ... }
Fired when an error response is received from the command
18 |
# File 'lib/mikrotik/command.rb', line 18 has_event :trap |
- (Object) where(conditions = {})
Adds querying conditions to the command
49 50 51 52 53 54 |
# File 'lib/mikrotik/command.rb', line 49 def where(conditions = {}) conditions.each_pair do |property, value| @options["?#{property}"] = value end self end |
- (Object) with(options = {})
Adds property names and values to the command
40 41 42 43 44 45 |
# File 'lib/mikrotik/command.rb', line 40 def with( = {}) .each_pair do |option, value| @options["=#{option}"] = value end self end |