Module: BinData::CopyOnChangePlugin

Defined in:
lib/bindata/choice.rb

Overview

Logic for the :copy_on_change parameter

Instance Method Summary collapse

Instance Method Details

#copy_previous_value(obj) ⇒ Object



169
170
171
172
173
174
# File 'lib/bindata/choice.rb', line 169

def copy_previous_value(obj)
  current_selection = selection
  prev = get_previous_choice(current_selection)
  obj.assign(prev) unless prev.nil?
  remember_current_selection(current_selection)
end

#current_choiceObject



163
164
165
166
167
# File 'lib/bindata/choice.rb', line 163

def current_choice
  obj = super
  copy_previous_value(obj)
  obj
end

#get_previous_choice(selection) ⇒ Object



176
177
178
179
180
# File 'lib/bindata/choice.rb', line 176

def get_previous_choice(selection)
  if @last_selection && selection != @last_selection
    @choices[@last_selection]
  end
end

#remember_current_selection(selection) ⇒ Object



182
183
184
# File 'lib/bindata/choice.rb', line 182

def remember_current_selection(selection)
  @last_selection = selection
end