Class: Brandish::Configure
- Inherits:
-
Object
- Object
- Brandish::Configure
- Extended by:
- Forwardable
- Defined in:
- lib/brandish/configure.rb,
lib/brandish/configure/dsl.rb,
lib/brandish/configure/form.rb,
lib/brandish/configure/dsl/form.rb
Overview
This provides a central location for all configuration options. For the DSL, see DSL.
Defined Under Namespace
Instance Attribute Summary collapse
-
#forms ⇒ Set<Configure::Form>
readonly
The forms that are defined on this configuration instance.
-
#options ⇒ {::Symbol => ::Object}
readonly
The options.
Instance Method Summary collapse
-
#[](key) ⇒ ::Object
Sets a key on the options.
-
#[]=(key, value) ⇒ ::Object
Sets a key on the options.
-
#build(which = :all) {|build| ... } ⇒ void
Given a set of forms to build, it yields blocks that can be called to build a form.
-
#build!(which = :all) {|build| ... } ⇒ void
Given a set of forms to build, it yields blocks that can be called to build a form.
-
#fetch(key) ⇒ ::Object
Fetches a value at the given key, or provides a default if the key doesn't exist.
-
#initialize(root = Dir.pwd) ⇒ Configure
constructor
Initializes the configure instance.
-
#output ⇒ ::Pathname
Retrieves the output path.
-
#parse_from(path, short = path.relative_path_from(root)) ⇒ Parser::Root
Parses a file.
-
#root ⇒ ::Pathname
Retrieves the root path.
-
#roots ⇒ {::Pathname => Parser::Root}
A cache for all of the root nodes.
-
#sources ⇒ PathSet
Retrieves the source path.
-
#templates ⇒ PathSet
Retrieves the templates path.
Constructor Details
#initialize(root = Dir.pwd) ⇒ Configure
Initializes the configure instance.
82 83 84 85 86 87 |
# File 'lib/brandish/configure.rb', line 82 def initialize(root = Dir.pwd) root = ::Pathname.new(root) @options = { root: root, sources: PathSet.new, templates: PathSet.new } @forms = ::Set.new default_paths end |
Instance Attribute Details
#forms ⇒ Set<Configure::Form> (readonly)
The forms that are defined on this configuration instance.
29 30 31 |
# File 'lib/brandish/configure.rb', line 29 def forms @forms end |
#options ⇒ {::Symbol => ::Object} (readonly)
The options. These can be anything; predefined options are :root
,
:source
, :output
, and :templates
; for more information on those,
see #root, #sources, #output, and #templates for more information.
These options should not be accessed directly, but rather through their
accessors. Other options must be accessed through this.
24 25 26 |
# File 'lib/brandish/configure.rb', line 24 def @options end |
Instance Method Details
#[](key) ⇒ ::Object
Sets a key on the options. This gets an option that is used for all processors on the options.
75 |
# File 'lib/brandish/configure.rb', line 75 delegate [:[], :fetch] => :options |
#[]=(key, value) ⇒ ::Object
Sets a key on the options. This sets an option that is used for all processors on the options.
75 |
# File 'lib/brandish/configure.rb', line 75 delegate [:[], :fetch] => :options |
#build(which = :all) {|build| ... } ⇒ void
This method returns an undefined value.
Given a set of forms to build, it yields blocks that can be called to build a form.
132 133 134 135 |
# File 'lib/brandish/configure.rb', line 132 def build(which = :all) return to_enum(:build, which) unless block_given? select_forms(which).each { |f| yield proc { f.build(self) } } end |
#build!(which = :all) {|build| ... } ⇒ void
This method returns an undefined value.
Given a set of forms to build, it yields blocks that can be called to build a form.
This first clears the cache for file nodes.
149 150 151 152 153 |
# File 'lib/brandish/configure.rb', line 149 def build!(which = :all) return to_enum(:build!, which) unless block_given? @_roots = nil select_forms(which).each { |f| yield proc { f.build(self) } } end |
#fetch(key) ⇒ ::Object
Fetches a value at the given key, or provides a default if the key doesn't exist. If both a block and a default argument are given, the block form takes precedence.
75 |
# File 'lib/brandish/configure.rb', line 75 delegate [:[], :fetch] => :options |
#output ⇒ ::Pathname
Retrieves the output path. This is where the outputs for all of the forms should be located.
102 103 104 |
# File 'lib/brandish/configure.rb', line 102 def output fetch(:output) { root / "output" } end |
#parse_from(path, short = path.relative_path_from(root)) ⇒ Parser::Root
Parses a file. This bypasses the cache.
174 175 176 |
# File 'lib/brandish/configure.rb', line 174 def parse_from(path, short = path.relative_path_from(root)) Parser.new(Scanner.new(path.read, short, ).call).call end |
#root ⇒ ::Pathname
Retrieves the root path. This is where all of the other directories should be located, and where the configuration file should be located.
94 95 96 |
# File 'lib/brandish/configure.rb', line 94 def root fetch(:root) end |
#roots ⇒ {::Pathname => Parser::Root}
A cache for all of the root nodes. This is a regular hash; however, upon attempt to access an item that isn't already in the hash, it first parses the file at that item, and stores the result in the hash, returning the root node in the file. This is to cache files so that they do not get reparsed multiple times.
162 163 164 |
# File 'lib/brandish/configure.rb', line 162 def roots @_roots ||= ::Hash.new { |h, k| h[k] = parse_from(k) } end |
#sources ⇒ PathSet
Retrieves the source path. This is where the sources for all of the documents in the Brandish project are located.
110 111 112 |
# File 'lib/brandish/configure.rb', line 110 def sources fetch(:sources) end |
#templates ⇒ PathSet
Retrieves the templates path. This is where all of the templates for all of the forms should be located.
118 119 120 |
# File 'lib/brandish/configure.rb', line 118 def templates fetch(:templates) end |