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

Class Method Summary collapse

Class Attribute Details

.basepathObject

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`

Parameters:

  • template (String)

    the template name

  • directory (String)

    the directory path

Returns:

  • nil



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.

Parameters:

  • key (Any) (defaults to: nil)

    the key to lookup

Returns:

  • (Any)

    either the whole config or the value for ‘key`



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.

Parameters:

  • opts (Hash) (defaults to: {})

    an hash which will be merged into the local config

Returns:

  • nil



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

Parameters:

  • name (String)

    the template name

Returns:



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.

Parameters:

  • subcomponent (String) (defaults to: "")

    the subcomponent to look for

Returns:

  • (String)

    the path to the local Yop directory or its subcomponent



17
18
19
# File 'lib/yop/home.rb', line 17

def home(subcomponent = "")
  File.expand_path("#{@basepath}/#{subcomponent}")
end

.initObject

Initialize Yop’s local directory

Returns:

  • nil



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).

Returns:

  • (Nil)


34
35
36
# File 'lib/yop/config.rb', line 34

def reload!
  read_config
end

.templatesArray

Returns all the available templates.

Returns:

  • (Array)

    all the available templates



13
14
15
# File 'lib/yop/templates.rb', line 13

def templates
  Dir["#{Yop.home("templates")}/*"]
end

.versionString

Returns the current gem’s version.

Returns:

  • (String)

    the current gem’s version



5
6
7
# File 'lib/yop/version.rb', line 5

def self.version
  "0.0.3"
end