Module: Lifer
- Defined in:
- lib/lifer.rb,
lib/lifer/cli.rb,
lib/lifer/tag.rb,
lib/lifer/entry.rb,
lib/lifer/version.rb
Overview
The root Lifer module is a great entrypoint into the system, with convenience methods to access global resources like collections and configuration settings.
Defined Under Namespace
Modules: Dev, Shared, Utilities Classes: Brain, Builder, CLI, Collection, Config, Entry, Message, Selection, Tag, URIStrategy
Constant Summary collapse
- IGNORE_DIRECTORIES =
Lifer considers files and directories that have the following names or contain the following patterns special and ignoreable when they’re at the root of the Lifer project.
[ "assets", "bin", "vendor" ]
- IGNORE_PATTERNS =
Lifer projects ignore files and directories that contain particular patterns.
[ "^(\\.)", # Starts with a dot. "^(_)", # Starts with an underscore. "(\\/\\.)+" # Contains a dot directory. ] | IGNORE_DIRECTORIES.map { |d| "^(#{d})" }
- FRONTMATTER_REGEX =
We expect frontmatter in any file to be provided in the following format.
/^---\n(.*)---\n/m
- VERSION =
"0.10.1"
Class Method Summary collapse
-
.brain(root: Dir.pwd, config_file: nil) ⇒ Lifer::Brain
The first time ‘Lifer.brain` is referenced, we build a new `Lifer::Brain` object that is used and reused until the current process has ended.
-
.build!(environment: :build) ⇒ void
Initiates the Lifer build process.
-
.collections(without_selections: false) ⇒ Array<Lifer::Collection>
List all collections in the project.
-
.config_file ⇒ Pathname
Used to locate the configuration file being used by the current Lifer project.
-
.entry_manifest ⇒ Set
A set of all entries currently in the project.
-
.gem_root ⇒ String
This convenience method locates the Ruby gem root, which is always distinct from the Lifer project root.
-
.ignoreable?(directory_or_file) ⇒ boolean
Check if the given path matches the Lifer ignore patterns.
-
.manifest ⇒ Set
A set of all entries currently in the project.
-
.output_directory ⇒ Pathname
The build directory for the Lifer project.
-
.parallelism_disabled? ⇒ boolean
Returns false if the Lifer project will be built with parallelism.
-
.register_settings(setting, ...) ⇒ void
Register new settings so that they are “safe” and can be read from a Lifer configuration file.
-
.root ⇒ Lifer::Brain
The project brain.
-
.setting(..., collection: nil, strict: false) ⇒ String, NilClass
Given a path to a setting, with or without a collection scope, get the current configured value for that setting.
-
.settings ⇒ Hash
The project’s current settings tree.
-
.tag_manifest ⇒ Set<Lifer::Tag>
A set of all tags added to the project.
-
.tags ⇒ Array<Lifer::Tag>
All of the tags represented in Lifer entries for the current project.
Class Method Details
.brain(root: Dir.pwd, config_file: nil) ⇒ Lifer::Brain
The first time ‘Lifer.brain` is referenced, we build a new `Lifer::Brain` object that is used and reused until the current process has ended.
39 40 41 |
# File 'lib/lifer.rb', line 39 def brain(root: Dir.pwd, config_file: nil) @@brain ||= Lifer::Brain.init root:, config_file: end |
.build!(environment: :build) ⇒ void
This method returns an undefined value.
Initiates the Lifer build process.
48 |
# File 'lib/lifer.rb', line 48 def build!(environment: :build) = (brain.build! environment:) |
.collections(without_selections: false) ⇒ Array<Lifer::Collection>
List all collections in the project. By default, selections are also included.
56 57 58 59 60 |
# File 'lib/lifer.rb', line 56 def collections(without_selections: false) return brain.collections unless without_selections brain.collections.select { _1.class == Lifer::Collection } end |
.config_file ⇒ Pathname
Used to locate the configuration file being used by the current Lifer project.
66 |
# File 'lib/lifer.rb', line 66 def config_file = brain.config.file |
.entry_manifest ⇒ Set
A set of all entries currently in the project.
73 |
# File 'lib/lifer.rb', line 73 def entry_manifest = brain.entry_manifest |
.gem_root ⇒ String
This convenience method locates the Ruby gem root, which is always distinct from the Lifer project root. This is helpful, for example, if default templates provided by the gem are required in the current project.
80 |
# File 'lib/lifer.rb', line 80 def gem_root = File.dirname(__dir__) |
.ignoreable?(directory_or_file) ⇒ boolean
Check if the given path matches the Lifer ignore patterns.
86 87 88 |
# File 'lib/lifer.rb', line 86 def ignoreable?(directory_or_file) directory_or_file.match?(/#{IGNORE_PATTERNS.join("|")}/) end |
.manifest ⇒ Set
A set of all entries currently in the project.
95 |
# File 'lib/lifer.rb', line 95 def manifest = brain.manifest |
.output_directory ⇒ Pathname
The build directory for the Lifer project.
101 |
# File 'lib/lifer.rb', line 101 def output_directory = brain.output_directory |
.parallelism_disabled? ⇒ boolean
Returns false if the Lifer project will be built with parallelism. This should return false almost always–unless you’ve explicitly set the ‘LIFER_UNPARALLELIZED` environment variable before running the program.
This method is used internally by Lifer to determine whether features that would normally run in parallel should not run in parallel for some reason.
111 |
# File 'lib/lifer.rb', line 111 def parallelism_disabled? = ENV["LIFER_UNPARALLELIZED"].is_a?(String) |
.register_settings(setting, ...) ⇒ void
Register new settings so that they are “safe” and can be read from a Lifer configuration file. Unregistered settings are ignored.
128 |
# File 'lib/lifer.rb', line 128 def register_settings(*settings) = brain.config.register_settings(*settings) |
.setting(..., collection: nil, strict: false) ⇒ String, NilClass
Given a path to a setting, with or without a collection scope, get the current configured value for that setting.
Note that if a collection does not have a setting set, the setting returned will be the Lifer root collection setting or the default setting unless the ‘:strict` keyword argument is set to `true`.
150 151 152 |
# File 'lib/lifer.rb', line 150 def setting(*name, collection: nil, strict: false) brain.setting *name, collection: collection, strict: strict end |
.settings ⇒ Hash
The project’s current settings tree.
157 |
# File 'lib/lifer.rb', line 157 def settings = brain.config.settings |
.tag_manifest ⇒ Set<Lifer::Tag>
A set of all tags added to the project. Prefer using the ‘#tags` method for tag queries.
168 |
# File 'lib/lifer.rb', line 168 def tag_manifest = brain.tag_manifest |
.tags ⇒ Array<Lifer::Tag>
All of the tags represented in Lifer entries for the current project.
162 |
# File 'lib/lifer.rb', line 162 def = brain. |