Class: Ramix::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/ramix/template.rb

Constant Summary collapse

DIR_PATH =
File.expand_path(File.dirname(__FILE__) + '/../../recipes')
THOR_CLASS_OPTION =
%w(desc required default aliases type banner group)
SELF_ATTRIBUTE =
%w(dependence)
ATTRIBUTE =
THOR_CLASS_OPTION + SELF_ATTRIBUTE

Instance Method Summary collapse

Constructor Details

#initialize(name, path = nil) ⇒ Template

Returns a new instance of Template.



11
12
13
14
15
16
17
18
19
20
# File 'lib/ramix/template.rb', line 11

def initialize(name, path = nil)
  @name = name
  @path = path || DIR_PATH
  begin
    draft, attribute, @output = File.read( File.join(@path, name + '.rb') ).split('---')
    @attribute                = YAML.load(attribute)
  rescue
    @attribute, @output       = {}, "\n\ngem '#{name}'"
  end
end

Instance Method Details

#nameObject



22
23
24
# File 'lib/ramix/template.rb', line 22

def name
  @attribute['name'] || @name
end

#orderObject



26
27
28
# File 'lib/ramix/template.rb', line 26

def order
  @attribute['order'] || 0
end

#output(*args) ⇒ Object



38
39
40
41
42
43
# File 'lib/ramix/template.rb', line 38

def output(*args)
  <<-OUTPUT
  instance_variable_set '@#{name}', #{args.dup.pop.inspect}
  #{@output}
  OUTPUT
end