Class: ArchSpec::Definition

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

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) ⇒ Definition

Returns a new instance of Definition.



21
22
23
24
25
26
27
28
29
# File 'lib/archspec/definition.rb', line 21

def initialize(name)
  @name = name
  @root_path = "."
  @baseline_path = nil
  @source_patterns = []
  @ignore_patterns = DEFAULT_IGNORE_PATTERNS.dup
  @component_specs = {}
  @rules = []
end

Instance Attribute Details

#baseline_pathObject

Returns the value of attribute baseline_path.



18
19
20
# File 'lib/archspec/definition.rb', line 18

def baseline_path
  @baseline_path
end

#component_specsObject (readonly)

Returns the value of attribute component_specs.



19
20
21
# File 'lib/archspec/definition.rb', line 19

def component_specs
  @component_specs
end

#ignore_patternsObject (readonly)

Returns the value of attribute ignore_patterns.



19
20
21
# File 'lib/archspec/definition.rb', line 19

def ignore_patterns
  @ignore_patterns
end

#nameObject

Returns the value of attribute name.



18
19
20
# File 'lib/archspec/definition.rb', line 18

def name
  @name
end

#root_pathObject

Returns the value of attribute root_path.



18
19
20
# File 'lib/archspec/definition.rb', line 18

def root_path
  @root_path
end

#rulesObject (readonly)

Returns the value of attribute rules.



19
20
21
# File 'lib/archspec/definition.rb', line 19

def rules
  @rules
end

#source_patternsObject (readonly)

Returns the value of attribute source_patterns.



19
20
21
# File 'lib/archspec/definition.rb', line 19

def source_patterns
  @source_patterns
end

Instance Method Details

#absolute_root(base_dir = Dir.pwd) ⇒ Object



55
56
57
# File 'lib/archspec/definition.rb', line 55

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

#add_component(spec) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/archspec/definition.rb', line 39

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



35
36
37
# File 'lib/archspec/definition.rb', line 35

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

#add_rule(rule) ⇒ Object



51
52
53
# File 'lib/archspec/definition.rb', line 51

def add_rule(rule)
  rules << rule
end

#add_source_patterns(patterns) ⇒ Object



31
32
33
# File 'lib/archspec/definition.rb', line 31

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

#analysis_patternsObject



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

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)


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

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