module Cog::Config
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.
Attributes
@return [Array<String>] directories in which to find generators
@return [Array<String>] directories in which to find plugins
@return [Array<String>] directories in which to find templates
Public Instance Methods
@return [String] Location of the installed cog gem
# 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
@return [String,nil] if installed as a gem, return the parent directory of the gem's location
# 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
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. @option opt [Boolean] :fullpaths (false) when listing files, full paths should be shown @option opt [Boolean] :minimal (false) only load the built-in Cogfile @option opt [String] :project_cogfile_path (nil) explicitly specify the location of the project {DSL::Cogfile}. If not provided, it will be searched for. If none can be found, {#project?} will be false
# 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
@return [Boolean] when listing files, full paths should be shown
# File lib/cog/config.rb, line 52 def show_fullpaths? @fullpaths end
@return [String] Path to the current user's cogfile
# File lib/cog/config.rb, line 47 def user_cogfile File.join user_dir, 'Cogfile' end
@return [String] Path to ${HOME}/.cog
# File lib/cog/config.rb, line 42 def user_dir File.expand_path File.join(ENV['HOME'], '.cog') end
Private Instance Methods
# File lib/cog/config.rb, line 125 def build_language_extension_map @language.each_value do |lang| lang.extensions.each do |ext| @language_extension_map[ext] = lang.key unless @language_extension_map.member?(ext) end end end
@return [String] path to the built-in cogfile
# File lib/cog/config.rb, line 149 def built_in_cogfile File.join gem_dir, 'BuiltIn.cogfile' end
The {DSL::Cogfile} will be looked for in the present working directory. If none is found there the parent directory will be checked, and then the grandparent, and so on.
@return [Config, nil] the singleton instance
# File lib/cog/config.rb, line 138 def find_default_cogfile parts = Dir.pwd.split File::SEPARATOR i = parts.length while i >= 0 && !File.exists?(File.join(parts.slice(0, i) + ['Cogfile'])) i -= 1 end path = File.join(parts.slice(0, i) + ['Cogfile']) if i >= 0 (path && File.exists?(path)) ? path : nil end
# File lib/cog/config.rb, line 112 def post_cogfile_processing @language.each_value do |lang| if lang.comment_style != lang.key other = @language[lang.comment_style] lang.apply_comment_style other end if lang.include_guard_style != lang.key other = @language[lang.include_guard_style] lang.apply_include_guard_style other end end end
@param path [String] path to the cogfile @option opt [Boolean] :plugin_path_only (false) only process plugin_path
calls in the given cogfile @option opt [Boolean] :active_plugin (false) process the stamp_generator
call in the given cogfile @option opt [Plugin] :plugin (nil) indicate that the cogfile is for the given plugin
# File lib/cog/config.rb, line 107 def process_cogfile(path, opt={}) cogfile = DSL::Cogfile.new self, path, opt cogfile.interpret end
@option opt [Boolean] :minimal (false) only load the built-in Cogfile @option opt [String] :project_cogfile_path (nil) project cogfile
# File lib/cog/config.rb, line 87 def process_cogfiles(opt={}) @project_cogfile_path = opt[:project_cogfile_path] || find_default_cogfile if @project_cogfile_path @project_cogfile_path = File.expand_path @project_cogfile_path @project_root = File.dirname @project_cogfile_path end process_cogfile built_in_cogfile return if opt[:minimal] process_cogfile user_cogfile if File.exists? user_cogfile process_cogfile @project_cogfile_path, :plugin_path_only => true if @project_cogfile_path plugins.each do |plugin| process_cogfile plugin.cogfile_path, :plugin => plugin end process_cogfile @project_cogfile_path, :project => true if @project_cogfile_path end