Module: Bcome::Selections
- Included in:
- Node::Estate, Bcome::Stack::Environment
- Defined in:
- lib/helpers/selections.rb
Instance Method Summary collapse
- #add(resource_identifier = nil) ⇒ Object
- #add! ⇒ Object
- #add_object(object) ⇒ Object
- #clear! ⇒ Object
- #find_resource_by_identifier(resource_identifier) ⇒ Object
- #get(remote_path) ⇒ Object
- #in_resources?(object) ⇒ Boolean
- #manage_object(method, resource_identifier = nil) ⇒ Object
- #no_selections? ⇒ Boolean
- #no_selections_error ⇒ Object
- #object_in_selections?(object) ⇒ Boolean
- #put(local_path, remote_path, bootstrap = false) ⇒ Object
- #remove(resource_identifier = nil) ⇒ Object
- #remove_object(object) ⇒ Object
-
#run(raw_commands, bootstrap = false) ⇒ Object
Runs commands over every object in the selection.
- #selections ⇒ Object
Instance Method Details
#add(resource_identifier = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/helpers/selections.rb', line 52 def add(resource_identifier = nil) if resource_identifier.is_a?(Array) resource_identifier.each do |ri| manage_object(:add_object, ri) end else manage_object(:add_object, resource_identifier) end end |
#add! ⇒ Object
72 73 74 75 |
# File 'lib/helpers/selections.rb', line 72 def add! @objects = resources puts "All nodes added".informational end |
#add_object(object) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/helpers/selections.rb', line 90 def add_object(object) return if object_in_selections?(object) @objects = @objects ? (@objects << object) : [object] puts "\n" + "#{object.identifier} added.". + "\sType 'selections' to see currently selections instances.'". return end |
#clear! ⇒ Object
77 78 79 80 |
# File 'lib/helpers/selections.rb', line 77 def clear! @objects = [] selections end |
#find_resource_by_identifier(resource_identifier) ⇒ Object
82 83 84 |
# File 'lib/helpers/selections.rb', line 82 def find_resource_by_identifier(resource_identifier) resources.select{|r| r.identifier == resource_identifier }.first end |
#get(remote_path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/helpers/selections.rb', line 41 def get(remote_path) if no_selections? no_selections_error return end @objects.each do |object| object.get(remote_path) end return end |
#in_resources?(object) ⇒ Boolean
86 87 88 |
# File 'lib/helpers/selections.rb', line 86 def in_resources?(object) resources.include?(object) end |
#manage_object(method, resource_identifier = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/helpers/selections.rb', line 3 def manage_object(method, resource_identifier = nil) unless resource_identifier && resource_identifier.is_a?(String) print "You must select a resource identified by its name. #{}".headsup else object = find_resource_by_identifier(resource_identifier) unless object print "Cannot find object with identifier #{resource_identifier} within the resources for this collection. #{}".failure unless object else send(method, object) end end end |
#no_selections? ⇒ Boolean
25 26 27 |
# File 'lib/helpers/selections.rb', line 25 def no_selections? !@objects || @objects.empty? end |
#no_selections_error ⇒ Object
122 123 124 |
# File 'lib/helpers/selections.rb', line 122 def no_selections_error puts "No nodes selected".informational end |
#object_in_selections?(object) ⇒ Boolean
108 109 110 111 |
# File 'lib/helpers/selections.rb', line 108 def object_in_selections?(object) return false unless @objects return @objects.include?(object) end |
#put(local_path, remote_path, bootstrap = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/helpers/selections.rb', line 29 def put(local_path, remote_path, bootstrap = false) if no_selections? no_selections_error return end @objects.each do |object| object.put(local_path, remote_path, bootstrap) end return end |
#remove(resource_identifier = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/helpers/selections.rb', line 62 def remove(resource_identifier = nil) if resource_identifier.is_a?(Array) resource_identifier.each do |ri| manage_object(:remove_object, ri) end else manage_object(:remove_object, resource_identifier) end end |
#remove_object(object) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/helpers/selections.rb', line 97 def remove_object(object) return if no_selections? unless object_in_selections?(object) puts "\n#{object.identifier} is not within selections".headsup else @objects = @objects - [object] puts "\n" + "#{object.identifier} removed.". + "\sType 'selections' to see currently selections instances.'". end return end |
#run(raw_commands, bootstrap = false) ⇒ Object
Runs commands over every object in the selection
17 18 19 20 21 22 23 |
# File 'lib/helpers/selections.rb', line 17 def run(raw_commands, bootstrap = false) return unless @objects @objects.each do |object| object.run(raw_commands, bootstrap) end return end |
#selections ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/helpers/selections.rb', line 113 def selections if no_selections? puts "\n" + "No added nodes.".headsup + "\n" else puts "\n\s\s" + "Selected nodes:". + "\n\n" puts @objects.collect {|o| o.do_describe }.join + "\n" end end |