Module: Ruckus::StructureAllowFieldReplacement

Included in:
Structure
Defined in:
lib/ruckus/structure/replacement.rb

Instance Method Summary collapse

Instance Method Details

#template_entry_added_hook(obj) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruckus/structure/replacement.rb', line 3

def template_entry_added_hook(obj)
    ## -------------------------------------------
    ## a quick dance to allow fields to replace other
    ## fields

    # check to see if it already exists, in which
    # case we want to replace the previous definition
    found = false
    @value.each_with_index do |x,i|
        if x.try(:name) == obj.try(:name)
            found = i
            break
        end
    end

    # it didn't exist, so add it to the structure
    if found
        # it did exist, so update the names index
        # and the previous entry in the structure

        self.class.structure_field_names[obj.try(:name)] = found
        @value[found] = obj
    else
        false
    end
end