Class: Patch::Patch

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/patch.rb

Overview

A single patch consisting of a node mapping and actions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, maps, actions) ⇒ Patch

Returns a new instance of Patch.

Parameters:

  • name (Symbol, String)
  • maps (Array<Node::Map>, Node::Map)

    A node map or maps

  • actions (Array<Hash>, Hash)

    An action or actions



11
12
13
14
# File 'lib/patch/patch.rb', line 11

def initialize(name, maps, actions)
  @name = name
  populate(maps, actions)
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/patch/patch.rb', line 6

def actions
  @actions
end

#mapsObject (readonly)

Returns the value of attribute maps.



6
7
8
# File 'lib/patch/patch.rb', line 6

def maps
  @maps
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/patch/patch.rb', line 6

def name
  @name
end

Instance Method Details

#default_messagesArray<Patch::Message>

Patch messages for the default values in the patch

Returns:



18
19
20
21
22
23
24
25
26
27
# File 'lib/patch/patch.rb', line 18

def default_messages
  actions_with_default = @actions.select do |action|
    !action[:default].nil? && !action[:default][:value].nil?
  end
  actions_with_default.map do |action|
    value = action[:default][:value]
    index = @actions.index(action)
    Message.new(:index => index, :patch_name => @name, :value => value)
  end
end

#enableBoolean

Enable the given nodes to implement this patch

Parameters:

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/patch/patch.rb', line 32

def enable
  result = @maps.map { |map| map.enable(self) }
  result.any?
end