Module: Yop
- Defined in:
- lib/yop.rb,
lib/yop/ui.rb,
lib/yop/home.rb,
lib/yop/config.rb,
lib/yop/version.rb,
lib/yop/bootstrap.rb,
lib/yop/templates.rb
Overview
Base module for Yop
Defined Under Namespace
Classes: Template, TerminalUI, UI
Class Attribute Summary collapse
-
.basepath ⇒ Object
let applications change the base path.
Class Method Summary collapse
-
.bootstrap(template, directory) ⇒ Object
Bootstrap a project (which will be) located in ‘directory` with the template `template`.
-
.config(key = nil) ⇒ Any
Get the local Yop config.
-
.config!(opts = {}) ⇒ Object
Set variables in the local Yop config.
-
.get_template(name) ⇒ Yop::Template
Retrieve a template from its name, or raise a ‘NonExistentTemplate` exception if it doesn’t exist.
-
.home(subcomponent = "") ⇒ String
Return the local Yop directory location.
-
.init ⇒ Object
Initialize Yop’s local directory.
-
.reload! ⇒ Nil
Force-reload the config.
-
.templates ⇒ Array
All the available templates.
-
.version ⇒ String
The current gem’s version.
Class Attribute Details
.basepath ⇒ Object
let applications change the base path
11 12 13 |
# File 'lib/yop/home.rb', line 11 def basepath @basepath end |
Class Method Details
.bootstrap(template, directory) ⇒ Object
Bootstrap a project (which will be) located in ‘directory` with the template `template`
12 13 14 |
# File 'lib/yop/bootstrap.rb', line 12 def bootstrap(template, directory) get_template(template).apply directory end |
.config(key = nil) ⇒ Any
Get the local Yop config. If no argument is given the whole config is returned. If one is given, the corresponding value is returned.
13 14 15 16 17 18 19 20 21 |
# File 'lib/yop/config.rb', line 13 def config(key = nil) read_config unless @conf if !key.nil? @conf[key] else @conf end end |
.config!(opts = {}) ⇒ Object
Set variables in the local Yop config.
26 27 28 29 |
# File 'lib/yop/config.rb', line 26 def config!(opts = {}) @conf.update(opts) save_config end |
.get_template(name) ⇒ Yop::Template
Retrieve a template from its name, or raise a ‘NonExistentTemplate` exception if it doesn’t exist
21 22 23 24 25 |
# File 'lib/yop/templates.rb', line 21 def get_template(name) dirs = Dir["#{Yop.home("templates")}/#{name}"] fail NonExistentTemplate, name if dirs.empty? Template.new(dirs.first, config(:vars) || {}) end |
.home(subcomponent = "") ⇒ String
Return the local Yop directory location. If an argument is given, it assumes it’s a Yop subcomponent and returns its location.
17 18 19 |
# File 'lib/yop/home.rb', line 17 def home(subcomponent = "") File.("#{@basepath}/#{subcomponent}") end |
.init ⇒ Object
Initialize Yop’s local directory
23 24 25 26 27 |
# File 'lib/yop/home.rb', line 23 def init FileUtils.mkdir_p home FileUtils.mkdir_p home("templates") FileUtils.touch home("config.yml") end |
.reload! ⇒ Nil
Force-reload the config. This shouldn’t be needed unless you know what you’re doing (e.g. testing the module).
34 35 36 |
# File 'lib/yop/config.rb', line 34 def reload! read_config end |
.templates ⇒ Array
Returns all the available templates.
13 14 15 |
# File 'lib/yop/templates.rb', line 13 def templates Dir["#{Yop.home("templates")}/*"] end |
.version ⇒ String
Returns the current gem’s version.
5 6 7 |
# File 'lib/yop/version.rb', line 5 def self.version "0.0.3" end |