Class: Twine::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/twine/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



9
10
11
12
# File 'lib/twine/plugin.rb', line 9

def initialize
  @debug = false
  require_gems
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/twine/plugin.rb', line 7

def config
  @config
end

#debugObject (readonly)

Returns the value of attribute debug.



7
8
9
# File 'lib/twine/plugin.rb', line 7

def debug
  @debug
end

Instance Method Details

#require_gemsObject

require gems from the yaml config.

gems: [twine-plugin1, twine-2]

also works with single gem

gems: twine-plugin1



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/twine/plugin.rb', line 23

def require_gems
  # ./twine.yml    # current working directory
  # ~/.twine       # home directory
  # /etc/twine.yml # etc
  cwd_config  = join_path Dir.pwd, 'twine.yml'
  home_config = join_path Dir.home, '.twine'
  etc_config  = '/etc/twine.yml'

  config_order = [cwd_config, home_config, etc_config]

  puts "Config order: #{config_order}" if debug

  config_order.each do |config_file|
    next unless valid_file config_file
    puts "Loading: #{config_file}" if debug
    @config = SafeYAML.load_file config_file
    puts "Config yaml: #{config}" if debug
    break
  end

  return unless config

  # wrap gems in an array. if nil then array will be empty
  Kernel.Array(config['gems']).each do |gem_path|
    puts "Requiring: #{gem_path}" if debug
    require gem_path
  end
end