Class: Dde::App
Overview
Class encapsulates DDE application. Dde::App serves as a base for more specific types,
- such as Dde::Server or Dde
-
Client.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#init_flags ⇒ Object
readonly
Returns the value of attribute init_flags.
Instance Method Summary collapse
- #dde_active? ⇒ Boolean
-
#error(message = nil) ⇒ Object
Raises Runtime error with message based on given message (DdeGetLastError message if no message given).
-
#initialize(init_flags = nil, &dde_callback) ⇒ App
constructor
Creates new DDE application (and starts DDE instance if dde_callback block is attached).
-
#start_dde(init_flags = nil, &dde_callback) ⇒ Object
(Re)Initialize application with DDEML library, providing attached dde callback either preserved @init_flags or init_flags argument are used.
-
#stop_dde ⇒ Object
(Re)Initialize application with DDEML library, providing attached dde callback.
-
#try(action, error_type = Dde::Errors::InitError) ⇒ Object
Expects a block, yields to it inside a rescue block, raises given error_type with extended fail message.
Constructor Details
#initialize(init_flags = nil, &dde_callback) ⇒ App
Creates new DDE application (and starts DDE instance if dde_callback block is attached)
28 29 30 31 32 33 |
# File 'lib/dde/app.rb', line 28 def initialize( init_flags=nil, &dde_callback ) @init_flags = init_flags start_dde init_flags, &dde_callback if dde_callback end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/dde/app.rb', line 25 def id @id end |
#init_flags ⇒ Object (readonly)
Returns the value of attribute init_flags.
25 26 27 |
# File 'lib/dde/app.rb', line 25 def init_flags @init_flags end |
Instance Method Details
#dde_active? ⇒ Boolean
87 88 89 |
# File 'lib/dde/app.rb', line 87 def dde_active? !!@id end |
#error(message = nil) ⇒ Object
Raises Runtime error with message based on given message (DdeGetLastError message if no message given)
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dde/app.rb', line 76 def error( = nil ) raise case when Integer Dde::Errors[] when nil Dde::Errors[dde_get_last_error(@id)] else end end |
#start_dde(init_flags = nil, &dde_callback) ⇒ Object
(Re)Initialize application with DDEML library, providing attached dde callback either preserved @init_flags or init_flags argument are used
46 47 48 49 50 51 52 53 |
# File 'lib/dde/app.rb', line 46 def start_dde( init_flags=nil, &dde_callback ) @init_flags = init_flags || @init_flags || APPCLASS_STANDARD try "Starting DDE" do @id, status = dde_initialize @id, @init_flags, &dde_callback error(status) unless @id && status == DMLERR_NO_ERROR end end |
#stop_dde ⇒ Object
(Re)Initialize application with DDEML library, providing attached dde callback
56 57 58 59 60 61 62 |
# File 'lib/dde/app.rb', line 56 def stop_dde try "Stopping DDE" do error "DDE not started" unless dde_active? error unless dde_uninitialize(@id) # Uninitialize app with DDEML library @id = nil # Clear instance id if uninitialization successful end end |
#try(action, error_type = Dde::Errors::InitError) ⇒ Object
Expects a block, yields to it inside a rescue block, raises given error_type with extended fail message. Returns self in case of success (to enable method chaining).
66 67 68 69 70 71 72 73 |
# File 'lib/dde/app.rb', line 66 def try( action, error_type=Dde::Errors::InitError ) begin yield rescue => e raise error_type, action + " failed with: #{e}" end self end |