Class: IronNails::View::Command
- Inherits:
-
Object
- Object
- IronNails::View::Command
- Includes:
- Core::Observable, Logging::ClassLogger
- Defined in:
- lib/ironnails/view/commands/command.rb
Overview
The base class for view commands in IronNails.
Direct Known Subclasses
AddSubViewCommand, BehaviorCommand, EventCommand, TimedCommand
Instance Attribute Summary collapse
-
#action ⇒ Object
the action that will be triggered.
-
#callback ⇒ Object
for asynchronous actions this gets executed after the view has been refreshed as a new command.
-
#condition ⇒ Object
the predicate that decides whether this command can execute or not.
-
#controller ⇒ Object
the name of the controller that built this command.
-
#mode ⇒ Object
indicates whether to execute this command on the ui thread or on a different thread.
-
#name ⇒ Object
the name of this command.
-
#view ⇒ Object
the view this command is bound to.
Instance Method Summary collapse
- #<=>(command) ⇒ Object (also: #compare_to)
- #==(command) ⇒ Object (also: #===, #equals)
- #asynchronous? ⇒ Boolean
- #attached? ⇒ Boolean
- #can_execute? ⇒ Boolean
-
#changed? ⇒ Boolean
flag to indicate whether this command needs a refresh in the view model.
-
#execute ⇒ Object
executes this command (it calls the action).
- #has_callback? ⇒ Boolean
-
#initialize(options) ⇒ Command
constructor
A new instance of Command.
- #read_options(options) ⇒ Object
- #refresh_view ⇒ Object
- #synchronise_viewmodel_with_controller ⇒ Object
Methods included from Core::Observable
#add_observer, #count_observers, #delete_observer, #delete_observers, #notify_observers
Methods included from Logging::ClassLogger
Constructor Details
#initialize(options) ⇒ Command
Returns a new instance of Command.
32 33 34 |
# File 'lib/ironnails/view/commands/command.rb', line 32 def initialize() end |
Instance Attribute Details
#action ⇒ Object
the action that will be triggered
21 22 23 |
# File 'lib/ironnails/view/commands/command.rb', line 21 def action @action end |
#callback ⇒ Object
for asynchronous actions this gets executed after the view has been refreshed as a new command
30 31 32 |
# File 'lib/ironnails/view/commands/command.rb', line 30 def callback @callback end |
#condition ⇒ Object
the predicate that decides whether this command can execute or not
24 25 26 |
# File 'lib/ironnails/view/commands/command.rb', line 24 def condition @condition end |
#controller ⇒ Object
the name of the controller that built this command
27 28 29 |
# File 'lib/ironnails/view/commands/command.rb', line 27 def controller @controller end |
#mode ⇒ Object
indicates whether to execute this command on the ui thread or on a different thread.
15 16 17 |
# File 'lib/ironnails/view/commands/command.rb', line 15 def mode @mode end |
#name ⇒ Object
the name of this command
18 19 20 |
# File 'lib/ironnails/view/commands/command.rb', line 18 def name @name end |
#view ⇒ Object
the view this command is bound to
12 13 14 |
# File 'lib/ironnails/view/commands/command.rb', line 12 def view @view end |
Instance Method Details
#<=>(command) ⇒ Object Also known as: compare_to
92 93 94 |
# File 'lib/ironnails/view/commands/command.rb', line 92 def <=>(command) self.name <=> command.name end |
#==(command) ⇒ Object Also known as: ===, equals
85 86 87 |
# File 'lib/ironnails/view/commands/command.rb', line 85 def ==(command) self.name == command.name end |
#asynchronous? ⇒ Boolean
54 55 56 |
# File 'lib/ironnails/view/commands/command.rb', line 54 def asynchronous? mode == :asynchronous end |
#attached? ⇒ Boolean
71 72 73 |
# File 'lib/ironnails/view/commands/command.rb', line 71 def attached? !view.nil? end |
#can_execute? ⇒ Boolean
50 51 52 |
# File 'lib/ironnails/view/commands/command.rb', line 50 def can_execute? !!(condition.nil?||condition.call) end |
#changed? ⇒ Boolean
flag to indicate whether this command needs a refresh in the view model
46 47 48 |
# File 'lib/ironnails/view/commands/command.rb', line 46 def changed? !!@changed end |
#execute ⇒ Object
executes this command (it calls the action)
76 77 78 79 80 81 82 83 |
# File 'lib/ironnails/view/commands/command.rb', line 76 def execute #log_on_error do puts "calling the action" synchronise_viewmodel_with_controller action.call refresh_view unless asynchronous? #end if can_execute? end |
#has_callback? ⇒ Boolean
58 59 60 |
# File 'lib/ironnails/view/commands/command.rb', line 58 def has_callback? !callback.nil? end |
#read_options(options) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ironnails/view/commands/command.rb', line 36 def () raise ArgumentError.new("A name is necesary") if [:name].nil? raise ArgumentError.new("An action is necesary") if [:action].nil? .each do |k, v| instance_variable_set "@#{k}", v end @mode ||= :synchronous end |
#refresh_view ⇒ Object
62 63 64 65 |
# File 'lib/ironnails/view/commands/command.rb', line 62 def refresh_view callback.call if asynchronous? && has_callback? notify_observers :refreshing_view, self end |
#synchronise_viewmodel_with_controller ⇒ Object
67 68 69 |
# File 'lib/ironnails/view/commands/command.rb', line 67 def synchronise_viewmodel_with_controller notify_observers :reading_input, self end |