class Patch::Patch
A single patch consisting of a node mapping and actions
Attributes
actions[R]
maps[R]
name[R]
Public Class Methods
new(name, maps, actions)
click to toggle source
@param [Symbol, String] name @param [Array<Node::Map>, Node::Map
] maps A node map or maps @param [Array<Hash>, Hash] actions An action or actions
# File lib/patch/patch.rb, line 11 def initialize(name, maps, actions) @name = name populate(maps, actions) end
Public Instance Methods
default_messages()
click to toggle source
Patch
messages for the default values in the patch @return [Array<Patch::Message>]
# 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
enable()
click to toggle source
Enable the given nodes to implement this patch @param [Node::Container] nodes @return [Boolean]
# File lib/patch/patch.rb, line 32 def enable result = @maps.map { |map| map.enable(self) } result.any? end
Private Instance Methods
populate(maps, actions)
click to toggle source
populate_actions(actions)
click to toggle source
Populate the patch actions from various arg formats @param [Array<Hash>, Hash] actions @return [Array<Hash>]
# File lib/patch/patch.rb, line 52 def populate_actions(actions) @actions = actions.kind_of?(Hash) ? [actions] : actions end
populate_maps(maps)
click to toggle source
Populate the node maps from various arg formats @param [Array<Hash, Node::Map
>, Hash, Node::Map
] maps @return [Array<Node::Map>]
# File lib/patch/patch.rb, line 59 def populate_maps(maps) maps = [maps] unless maps.kind_of?(Array) maps = maps.map do |map| if map.kind_of?(Hash) Node::Map.new(map.keys.first, map.values.first) else map end end @maps = maps.flatten.compact end