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
- #identifier ⇒ Object
- #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
- #resources ⇒ Object
- #responds_to_list? ⇒ Boolean
Instance Method Details
#all_items ⇒ Object
65 66 67 68 |
# File 'lib/become_object.rb', line 65 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
53 54 55 56 |
# File 'lib/become_object.rb', line 53 def do_load_resources config = YAML.load_file(config_path) return 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 |
#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 |
#list ⇒ Object Also known as: ls
74 75 76 77 78 79 80 |
# File 'lib/become_object.rb', line 74 def list if responds_to_list? ::RENDER.list_items(collection_key, resources) else puts "\nNo list function at this level".headsup 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
58 59 60 61 62 63 |
# File 'lib/become_object.rb', line 58 def resource_for_identifier(identifier) return nil unless 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 |
#resources ⇒ Object
49 50 51 |
# File 'lib/become_object.rb', line 49 def resources @resources ||= do_load_resources end |
#responds_to_list? ⇒ Boolean
70 71 72 |
# File 'lib/become_object.rb', line 70 def responds_to_list? true end |