Module: Cog::Config

Includes:
LanguageConfig, PluginConfig, ProjectConfig
Included in:
Cog
Defined in:
lib/cog/config.rb,
lib/cog/config/plugin_config.rb,
lib/cog/config/project_config.rb,
lib/cog/config/language_config.rb

Overview

This is a low level interface. It is mainly used by the Generator methods to determine where to find things, and where to put them.

Defined Under Namespace

Modules: LanguageConfig, PluginConfig, ProjectConfig

Instance Attribute Summary collapse

Attributes included from ProjectConfig

#project_cogfile_path, #project_generator_path, #project_path, #project_plugin_path, #project_root, #project_template_path

Instance Method Summary collapse

Methods included from PluginConfig

#plugin, #plugins, #register_plugins

Methods included from LanguageConfig

#activate_language, #active_language, #language, #language_extensions, #language_for, #language_summary

Methods included from ProjectConfig

#project?, #supported_project_files

Instance Attribute Details

#generator_pathArray<String> (readonly)



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

def generator_path
  @generator_path
end

#plugin_pathArray<String> (readonly)



21
22
23
# File 'lib/cog/config.rb', line 21

def plugin_path
  @plugin_path
end

#template_pathArray<String> (readonly)



18
19
20
# File 'lib/cog/config.rb', line 18

def template_path
  @template_path
end

Instance Method Details

#gem_dirString



24
25
26
27
28
29
30
31
32
33
# File 'lib/cog/config.rb', line 24

def gem_dir
  spec = Gem.loaded_specs['cog']
  if spec.nil?
    # The current __FILE__ is:
    #   ${COG_GEM_ROOT}/lib/cog/config.rb
    File.expand_path File.join(File.dirname(__FILE__), '..', '..')
  else
    spec.gem_dir
  end
end

#gems_root_dirString?



36
37
38
39
# File 'lib/cog/config.rb', line 36

def gems_root_dir
  x = gem_dir
  File.expand_path(File.join(x, '..')) unless File.exists?(File.join(x, 'Gemfile'))
end

#prepare(opt = {}) ⇒ Object

Must be called once before using cog. In the context of a command-line invocation, this method will be called automatically. Outside of that context, for example in a unit test, it will have to be called manually.

Options Hash (opt):

  • :fullpaths (Boolean) — default: false

    when listing files, full paths should be shown

  • :minimal (Boolean) — default: false

    only load the built-in Cogfile

  • :project_cogfile_path (String) — default: nil

    explicitly specify the location of the project DSL::Cogfile. If not provided, it will be searched for. If none can be found, Cog::Config::ProjectConfig#project? will be false



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cog/config.rb', line 61

def prepare(opt={})
  throw :ConfigInstanceAlreadyPrepared if @prepared && !opt[:force_reset]
  @prepared = true
  @fullpaths = opt[:fullpaths]
  @project_path = nil
  @project_generator_path = nil
  @project_plugin_path = nil
  @project_template_path = nil
  @generator_path = []
  @plugin_path = []
  @template_path = []
  @plugins = {}
  @target_language = Language.new
  @active_languages = [Language.new] # active language stack
  @language = {}
  @language_extension_map = {}
  
  process_cogfiles opt
  post_cogfile_processing
  build_language_extension_map
end

#show_fullpaths?Boolean



52
53
54
# File 'lib/cog/config.rb', line 52

def show_fullpaths?
  @fullpaths
end

#user_cogfileString



47
48
49
# File 'lib/cog/config.rb', line 47

def user_cogfile
  File.join user_dir, 'Cogfile'
end

#user_dirString



42
43
44
# File 'lib/cog/config.rb', line 42

def user_dir
  File.expand_path File.join(ENV['HOME'], '.cog')
end