class Tailor::Configuration::FileSet

Constants

DEFAULT_GLOB

Attributes

file_list[RW]
style[R]

Public Class Methods

new(file_expression=nil, style=nil) click to toggle source

@param [Hash] style Style options to merge into the default Style

settings.

@param [String,Array] file_expression

# File lib/tailor/configuration/file_set.rb, line 18
def initialize(file_expression=nil, style=nil)
  @style = if style
    Style.new.to_hash.merge(style)
  else
    Style.new.to_hash
  end

  self[:style] = @style

  file_expression ||= DEFAULT_GLOB
  @file_list = build_file_list(file_expression)
  self[:file_list] = @file_list
end

Public Instance Methods

[](key) click to toggle source
# File lib/tailor/configuration/file_set.rb, line 41
def [](key)
  if key == :style
    @style.to_hash
  elsif key == :file_list
    @file_list
  else
    raise Tailor::RuntimeError, "Invalid key requested: #{key}"
  end
end
file_list=(file_expression) click to toggle source
# File lib/tailor/configuration/file_set.rb, line 51
def file_list=(file_expression)
  @file_list = build_file_list(file_expression)
end
update_file_list(file_expression) click to toggle source
# File lib/tailor/configuration/file_set.rb, line 32
def update_file_list(file_expression)
  new_list = build_file_list(file_expression)
  @file_list.concat(new_list).uniq!
end
update_style(new_style) click to toggle source
# File lib/tailor/configuration/file_set.rb, line 37
def update_style(new_style)
  @style.to_hash.merge!(new_style)
end

Private Instance Methods

all_files_in_dir(base_dir) click to toggle source

Gets a list of only files that are in base_dir.

@param [String] base_dir The directory to get the file list for. @return [Array<String>] The List of files.

# File lib/tailor/configuration/file_set.rb, line 101
def all_files_in_dir(base_dir)
  Dir.glob(File.join(base_dir, '**', '*')).find_all do |file|
    file if File.file?(file)
  end
end
build_file_list(file_expression) click to toggle source

The list of the files in the project to check.

@param [String] file_expression Path to the file, directory or file_expression to check. @return [Array] The list of files to check.

# File lib/tailor/configuration/file_set.rb, line 61
def build_file_list(file_expression)
  files_in_project = if file_expression.is_a? Array
    log "Configured file_expression is an Array: #{file_expression}"

    file_expression.map do |e|
      if File.directory?(e)
        all_files_in_dir(e)
      else
        e
      end
    end.flatten.uniq
  elsif File.directory? file_expression
    log "Configured file_expression is an directory: #{file_expression}"
    all_files_in_dir(file_expression)
  elsif File.file? file_expression
    log "Configured file_expression is a single-file: #{file_expression}"
    [file_expression]
  else
    log "Configured file_expression is a glob: #{file_expression}"
    Dir.glob file_expression
  end

  list_with_absolute_paths = []

  files_in_project.each do |file|
    new_file = File.expand_path(file)
    log "file: #{new_file}"

    if File.exists? new_file
      list_with_absolute_paths <<  new_file
    end
  end

  list_with_absolute_paths.sort
end