Class: MOSAIK::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaik/configuration.rb

Overview

Configuration parser (mosaik.yml)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory:, load_paths: [], includes: [], excludes: [], overrides: {}, collapsed: []) ⇒ Configuration

Returns a new instance of Configuration.



10
11
12
13
14
15
16
17
# File 'lib/mosaik/configuration.rb', line 10

def initialize(directory:, load_paths: [], includes: [], excludes: [], overrides: {}, collapsed: [])
  @directory = directory
  @load_paths = load_paths
  @includes = includes
  @excludes = excludes
  @overrides = overrides
  @collapsed = collapsed
end

Instance Attribute Details

#collapsedObject (readonly)

Returns the value of attribute collapsed.



8
9
10
# File 'lib/mosaik/configuration.rb', line 8

def collapsed
  @collapsed
end

#excludesObject (readonly)

Returns the value of attribute excludes.



8
9
10
# File 'lib/mosaik/configuration.rb', line 8

def excludes
  @excludes
end

#includesObject (readonly)

Returns the value of attribute includes.



8
9
10
# File 'lib/mosaik/configuration.rb', line 8

def includes
  @includes
end

#load_pathsObject (readonly)

Returns the value of attribute load_paths.



8
9
10
# File 'lib/mosaik/configuration.rb', line 8

def load_paths
  @load_paths
end

#overridesObject (readonly)

Returns the value of attribute overrides.



8
9
10
# File 'lib/mosaik/configuration.rb', line 8

def overrides
  @overrides
end

Class Method Details

.from(file) ⇒ Object

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mosaik/configuration.rb', line 28

def self.from(file)
  raise ConfigurationError, "Configuration file not found: #{file}" unless File.exist?(file)

  configuration = YAML.load_file(file)

  new(
    directory: File.dirname(file),
    load_paths: Array(configuration["load_paths"]),
    includes: Array(configuration["include"]),
    excludes: Array(configuration["exclude"]),
    overrides: configuration["overrides"] || {},
    collapsed: Array(configuration["collapsed"]),
  )
end

Instance Method Details

#filesObject



19
20
21
22
23
24
25
26
# File 'lib/mosaik/configuration.rb', line 19

def files
  @files ||= begin
    included_files = Dir[*load_paths.flat_map { |p| includes.map { |i| File.join(directory, p, i) } }]
    excluded_files = Dir[*load_paths.flat_map { |p| excludes.map { |e| File.join(directory, p, e) } }]

    included_files - excluded_files
  end
end