Method: String#cog_source_and_type

Defined in:
lib/cog/native_extensions/string.rb

#cog_source_and_typeString

Returns source and type, where type is one of :project, :user, :built_in, :gem, or :unknown.

Returns:

  • (String, String)

    source and type, where type is one of :project, :user, :built_in, :gem, or :unknown



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cog/native_extensions/string.rb', line 45

def cog_source_and_type
  if ((Cog.project_root && start_with?(Cog.project_root)) ||
      (Cog.project_template_path && start_with?(Cog.project_template_path)) || 
      (Cog.project_generator_path && start_with?(Cog.project_generator_path)) ||
      (Cog.project_plugin_path && start_with?(Cog.project_plugin_path)))
    [File.basename(Cog.project_root), :project]
  elsif start_with? Cog.user_dir
    [File.basename(ENV['HOME']), :user]
  elsif start_with? Cog.gem_dir
    ['cog', :built_in]
  elsif start_with? File.expand_path(File.join(Cog.gem_dir, '..'))
    ['gem', :gem]
  else
    ['unknown', :unknown]
  end
end