Class: Ruco::History
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #add(state) ⇒ Object
-
#initialize(options) ⇒ History
constructor
A new instance of History.
- #redo ⇒ Object
- #state ⇒ Object
- #undo ⇒ Object
Constructor Details
#initialize(options) ⇒ History
Returns a new instance of History.
5 6 7 8 9 10 11 |
# File 'lib/ruco/history.rb', line 5 def initialize() @options = @stack = [@options.delete(:state)] @timeout = .delete(:timeout) || 0 timeout! @position = 0 end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/ruco/history.rb', line 3 def timeout @timeout end |
Instance Method Details
#add(state) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruco/history.rb', line 17 def add(state) return unless tracked_field_changes?(state) remove_undone_states if merge_timeout? @position += 1 @last_merge = Time.now.to_f end @stack[@position] = state limit_stack end |
#redo ⇒ Object
33 34 35 36 |
# File 'lib/ruco/history.rb', line 33 def redo timeout! @position = [@position + 1, @stack.size - 1].min end |
#state ⇒ Object
13 14 15 |
# File 'lib/ruco/history.rb', line 13 def state @stack[@position] end |
#undo ⇒ Object
28 29 30 31 |
# File 'lib/ruco/history.rb', line 28 def undo timeout! @position = [@position - 1, 0].max end |