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

Instance Method Details

#all_itemsObject



85
86
87
88
# File 'lib/become_object.rb', line 85

def all_items
  return [] unless resources
  resources.collect(&:identifier)
end

#become_identifierObject



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

def become_identifier
  "#{previous_workspace_object.send(:become_identifier)}> #{identifier}"
end

#context_breadcrumbObject



23
24
25
26
27
# File 'lib/become_object.rb', line 23

def context_breadcrumb
 breadcrumb = namespace.gsub("/", ":")
 breadcrumb.slice!(0)
 return breadcrumb
end

#do_load_resourcesObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/become_object.rb', line 45

def has_main_context?
  !@main_context.nil?
end

#has_potential_resources?Boolean

Returns:

  • (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

#identifierObject



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

Returns:

  • (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

#listObject 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".menu_item_white + "\n\n"
  end   
end

#local_download_pathObject



15
16
17
# File 'lib/become_object.rb', line 15

def local_download_path
  "#{Dir.pwd}/downloads#{namespace}" 
end

#main_contextObject



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

#namespaceObject



19
20
21
# File 'lib/become_object.rb', line 19

def namespace
  "#{previous_workspace_object.send(:namespace)}/#{identifier}"
end

#previous_workspace_objectObject



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_identifiersObject



53
54
55
# File 'lib/become_object.rb', line 53

def resource_identifiers
  @resource_identifiers ||= resources.collect(&:identifier)
end

#resourcesObject



49
50
51
# File 'lib/become_object.rb', line 49

def resources
  @resources ||= do_load_resources 
end

#responds_to_list?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/become_object.rb', line 90

def responds_to_list?
  true
end