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



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

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



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

def current_choice
  obj = super
  copy_previous_value(obj)
  obj
end

#get_previous_choice(selection) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/bindata/choice.rb', line 180

def get_previous_choice(selection)
  if selection != @last_selection and @last_selection != nil
    @choices[@last_selection]
  else
    nil
  end
end

#remember_current_selection(selection) ⇒ Object



188
189
190
# File 'lib/bindata/choice.rb', line 188

def remember_current_selection(selection)
  @last_selection = selection
end