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



172
173
174
175
176
177
# File 'lib/bindata/choice.rb', line 172

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



166
167
168
169
170
# File 'lib/bindata/choice.rb', line 166

def current_choice
  obj = super
  copy_previous_value(obj)
  obj
end

#get_previous_choice(selection) ⇒ Object



179
180
181
182
183
# File 'lib/bindata/choice.rb', line 179

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

#remember_current_selection(selection) ⇒ Object



185
186
187
# File 'lib/bindata/choice.rb', line 185

def remember_current_selection(selection)
  @last_selection = selection
end