Class: ArchSpec::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/definition.rb

Overview

The result of evaluating an Archspec.rb file: the project settings, declared components, and rules. ArchSpec::DSL::Context is mixed into an instance to provide the DSL, and the analyzer and evaluator read it to run the checks. Build one with ArchSpec.define.

Constant Summary collapse

DEFAULT_SOURCE_PATTERNS =
[
  'app/**/*.rb',
  'lib/**/*.rb',
  'packs/*/app/**/*.rb',
  'engines/*/app/**/*.rb'
].freeze
DEFAULT_IGNORE_PATTERNS =
[
  '.git/**/*',
  '.bundle/**/*',
  'node_modules/**/*',
  'tmp/**/*',
  'vendor/**/*'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Definition

Returns a new instance of Definition.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/archspec/definition.rb', line 27

def initialize(name = nil)
  @name = name
  @root_path = '.'
  @todo_path = nil
  @base_dir = nil
  @source_patterns = []
  @ignore_patterns = DEFAULT_IGNORE_PATTERNS.dup
  @component_specs = {}
  @rules = []
  @inflections = {}
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



24
25
26
# File 'lib/archspec/definition.rb', line 24

def base_dir
  @base_dir
end

#component_specsObject (readonly)

Returns the value of attribute component_specs.



25
26
27
# File 'lib/archspec/definition.rb', line 25

def component_specs
  @component_specs
end

#ignore_patternsObject (readonly)

Returns the value of attribute ignore_patterns.



25
26
27
# File 'lib/archspec/definition.rb', line 25

def ignore_patterns
  @ignore_patterns
end

#inflectionsObject (readonly)

Returns the value of attribute inflections.



25
26
27
# File 'lib/archspec/definition.rb', line 25

def inflections
  @inflections
end

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/archspec/definition.rb', line 24

def name
  @name
end

#root_pathObject

Returns the value of attribute root_path.



24
25
26
# File 'lib/archspec/definition.rb', line 24

def root_path
  @root_path
end

#rulesObject (readonly)

Returns the value of attribute rules.



25
26
27
# File 'lib/archspec/definition.rb', line 25

def rules
  @rules
end

#source_patternsObject (readonly)

Returns the value of attribute source_patterns.



25
26
27
# File 'lib/archspec/definition.rb', line 25

def source_patterns
  @source_patterns
end

#todo_pathObject

Returns the value of attribute todo_path.



24
25
26
# File 'lib/archspec/definition.rb', line 24

def todo_path
  @todo_path
end

Instance Method Details

#absolute_root(base = base_dir || Dir.pwd) ⇒ Object

The directory file patterns resolve against: root_path expanded from the directory the Archspec.rb was loaded from (base_dir), or the working directory when built without a file.



70
71
72
# File 'lib/archspec/definition.rb', line 70

def absolute_root(base = base_dir || Dir.pwd)
  File.expand_path(root_path, base)
end

#add_component(spec) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/archspec/definition.rb', line 51

def add_component(spec)
  if component_specs.key?(spec.name)
    component_specs.fetch(spec.name).merge!(spec)
  else
    component_specs[spec.name] = spec
  end
end

#add_ignore_patterns(patterns) ⇒ Object



47
48
49
# File 'lib/archspec/definition.rb', line 47

def add_ignore_patterns(patterns)
  @ignore_patterns |= Array(patterns).flatten.compact.map(&:to_s)
end

#add_inflections(map) ⇒ Object



39
40
41
# File 'lib/archspec/definition.rb', line 39

def add_inflections(map)
  @inflections.merge!(map.to_h.transform_keys(&:to_s).transform_values(&:to_s))
end

#add_rule(rule) ⇒ Object



63
64
65
# File 'lib/archspec/definition.rb', line 63

def add_rule(rule)
  rules << rule
end

#add_source_patterns(patterns) ⇒ Object



43
44
45
# File 'lib/archspec/definition.rb', line 43

def add_source_patterns(patterns)
  @source_patterns |= Array(patterns).flatten.compact.map(&:to_s)
end

#analysis_patternsObject



74
75
76
77
# File 'lib/archspec/definition.rb', line 74

def analysis_patterns
  patterns = source_patterns.empty? ? DEFAULT_SOURCE_PATTERNS.dup : source_patterns.dup
  patterns | component_specs.values.flat_map(&:file_patterns)
end

#component?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/archspec/definition.rb', line 59

def component?(name)
  component_specs.key?(name.to_sym)
end