Class: ArchSpec::Definition
- Inherits:
-
Object
- Object
- ArchSpec::Definition
- 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
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#component_specs ⇒ Object
readonly
Returns the value of attribute component_specs.
-
#ignore_patterns ⇒ Object
readonly
Returns the value of attribute ignore_patterns.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#source_patterns ⇒ Object
readonly
Returns the value of attribute source_patterns.
-
#todo_path ⇒ Object
Returns the value of attribute todo_path.
Instance Method Summary collapse
-
#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.
- #add_component(spec) ⇒ Object
- #add_ignore_patterns(patterns) ⇒ Object
- #add_rule(rule) ⇒ Object
- #add_source_patterns(patterns) ⇒ Object
- #analysis_patterns ⇒ Object
- #component?(name) ⇒ Boolean
-
#initialize(name = nil) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(name = nil) ⇒ Definition
Returns a new instance of Definition.
27 28 29 30 31 32 33 34 35 36 |
# 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 = [] end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
24 25 26 |
# File 'lib/archspec/definition.rb', line 24 def base_dir @base_dir end |
#component_specs ⇒ Object (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_patterns ⇒ Object (readonly)
Returns the value of attribute ignore_patterns.
25 26 27 |
# File 'lib/archspec/definition.rb', line 25 def ignore_patterns @ignore_patterns end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/archspec/definition.rb', line 24 def name @name end |
#root_path ⇒ Object
Returns the value of attribute root_path.
24 25 26 |
# File 'lib/archspec/definition.rb', line 24 def root_path @root_path end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
25 26 27 |
# File 'lib/archspec/definition.rb', line 25 def rules @rules end |
#source_patterns ⇒ Object (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_path ⇒ Object
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.
65 66 67 |
# File 'lib/archspec/definition.rb', line 65 def absolute_root(base = base_dir || Dir.pwd) File.(root_path, base) end |
#add_component(spec) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/archspec/definition.rb', line 46 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
42 43 44 |
# File 'lib/archspec/definition.rb', line 42 def add_ignore_patterns(patterns) @ignore_patterns |= Array(patterns).flatten.compact.map(&:to_s) end |
#add_rule(rule) ⇒ Object
58 59 60 |
# File 'lib/archspec/definition.rb', line 58 def add_rule(rule) rules << rule end |
#add_source_patterns(patterns) ⇒ Object
38 39 40 |
# File 'lib/archspec/definition.rb', line 38 def add_source_patterns(patterns) @source_patterns |= Array(patterns).flatten.compact.map(&:to_s) end |
#analysis_patterns ⇒ Object
69 70 71 72 |
# File 'lib/archspec/definition.rb', line 69 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
54 55 56 |
# File 'lib/archspec/definition.rb', line 54 def component?(name) component_specs.key?(name.to_sym) end |