Module: Bcome::BecomeObject
- Included in:
- Stack::Environment, Stack::Estate, Stack::Instance, Stack::Platform
- Defined in:
- lib/become_object.rb
Constant Summary collapse
- CONFIGS_PATH =
"bcome/config"
Instance Method Summary collapse
- #all_items ⇒ Object
- #become_identifier ⇒ Object
- #context_breadcrumb ⇒ Object
- #do_load_resources ⇒ Object
- #has_main_context? ⇒ Boolean
- #has_potential_resources? ⇒ Boolean
- #identifier ⇒ Object
- #identifier_for(resource) ⇒ Object
- #is_stack_level_resource?(constant_name) ⇒ Boolean
- #list ⇒ Object (also: #ls)
- #local_download_path ⇒ Object
- #main_context ⇒ Object
- #main_context=(main_context) ⇒ Object
- #namespace ⇒ Object
- #previous_workspace_object ⇒ Object
- #previous_workspace_object=(object) ⇒ Object
- #resource_for_identifier(identifier) ⇒ Object
- #resource_identifiers ⇒ Object
- #resources ⇒ Object
- #responds_to_list? ⇒ Boolean
Instance Method Details
#all_items ⇒ Object
85 86 87 88 |
# File 'lib/become_object.rb', line 85 def all_items return [] unless resources resources.collect(&:identifier) end |
#become_identifier ⇒ Object
11 12 13 |
# File 'lib/become_object.rb', line 11 def become_identifier "#{previous_workspace_object.send(:become_identifier)}> #{identifier}" end |
#context_breadcrumb ⇒ Object
23 24 25 26 27 |
# File 'lib/become_object.rb', line 23 def = namespace.gsub("/", ":") .slice!(0) return end |
#do_load_resources ⇒ Object
73 74 75 76 |
# File 'lib/become_object.rb', line 73 def do_load_resources config = YAML.load_file(config_path) collection_klass.collection_from_config(self, config) end |
#has_main_context? ⇒ Boolean
45 46 47 |
# File 'lib/become_object.rb', line 45 def has_main_context? !@main_context.nil? end |
#has_potential_resources? ⇒ Boolean
62 63 64 |
# File 'lib/become_object.rb', line 62 def has_potential_resources? respond_to?(:config_path) # No path to config, no resources... end |
#identifier ⇒ Object
7 8 9 |
# File 'lib/become_object.rb', line 7 def identifier raise "Missing method 'identifier' - this should uniquely identify your workspace context object." end |
#identifier_for(resource) ⇒ Object
57 58 59 60 |
# File 'lib/become_object.rb', line 57 def identifier_for(resource) r = resource.respond_to?(:identifier) ? resource.identifier : resource.to_s return r end |
#is_stack_level_resource?(constant_name) ⇒ Boolean
66 67 68 69 70 71 |
# File 'lib/become_object.rb', line 66 def is_stack_level_resource?(constant_name) return unless has_potential_resources? potential_resource_name = constant_name.to_s return false unless resource_identifiers.any? return resource_identifiers.select{|resource| identifier_for(resource) == potential_resource_name }.any? end |
#list ⇒ Object Also known as: ls
94 95 96 97 98 99 100 101 |
# File 'lib/become_object.rb', line 94 def list if responds_to_list? ::RENDER.list_items(collection_key, resources) else puts "\n" + "No list function at this level".warning + "\n\n" puts "Enter 'menu' for all available options". + "\n\n" end end |
#local_download_path ⇒ Object
15 16 17 |
# File 'lib/become_object.rb', line 15 def local_download_path "#{Dir.pwd}/downloads#{namespace}" end |
#main_context ⇒ Object
41 42 43 |
# File 'lib/become_object.rb', line 41 def main_context @main_context end |
#main_context=(main_context) ⇒ Object
37 38 39 |
# File 'lib/become_object.rb', line 37 def main_context=(main_context) @main_context = main_context end |
#namespace ⇒ Object
19 20 21 |
# File 'lib/become_object.rb', line 19 def namespace "#{previous_workspace_object.send(:namespace)}/#{identifier}" end |
#previous_workspace_object ⇒ Object
33 34 35 |
# File 'lib/become_object.rb', line 33 def previous_workspace_object @previous_workspace_object end |
#previous_workspace_object=(object) ⇒ Object
29 30 31 |
# File 'lib/become_object.rb', line 29 def previous_workspace_object=(object) @previous_workspace_object = object end |
#resource_for_identifier(identifier) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/become_object.rb', line 78 def resource_for_identifier(identifier) return nil unless has_sub_nodes? && resources matches = resources.select{|resource| resource.identifier.to_sym == identifier.to_sym } raise "Retrieved more than one match for #{collection_key} '#{identifier}'. Selection is ambiguous" if matches.size > 1 return matches.first end |
#resource_identifiers ⇒ Object
53 54 55 |
# File 'lib/become_object.rb', line 53 def resource_identifiers @resource_identifiers ||= resources.collect(&:identifier) end |
#resources ⇒ Object
49 50 51 |
# File 'lib/become_object.rb', line 49 def resources @resources ||= do_load_resources end |
#responds_to_list? ⇒ Boolean
90 91 92 |
# File 'lib/become_object.rb', line 90 def responds_to_list? true end |