Module: Generable

Included in:
Base
Defined in:
lib/aina/generable.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accepts?(type) ⇒ Boolean

Is generable?

Returns:

  • (Boolean)


16
17
18
# File 'lib/aina/generable.rb', line 16

def self.accepts?(type)
  generable_types.include?(type)
end

.class_name_for(type) ⇒ Object



11
12
13
# File 'lib/aina/generable.rb', line 11

def self.class_name_for(type)
  "Generable::#{type.camelcase}"
end

.generable_typesObject

List of generable types



3
4
5
6
7
8
9
# File 'lib/aina/generable.rb', line 3

def self.generable_types
  g = Array.new
  Dir.glob(File.dirname(__FILE__) + "/generable/types/*.rb").each do |f|
    g << f.split('/').last.split('.rb').join()
  end
  g
end

Instance Method Details

#after_generate(*callbacks) ⇒ Object



55
56
57
# File 'lib/aina/generable.rb', line 55

def after_generate(*callbacks)
  @after_generate = callbacks
end

#dir(directory) ⇒ Object

Does type need to be created in a directory? Then, in type use: dir ‘my-directory’



23
24
25
# File 'lib/aina/generable.rb', line 23

def dir(directory)
  @dir = directory
end

#get_after_generateObject



59
60
61
# File 'lib/aina/generable.rb', line 59

def get_after_generate
  @after_generate
end

#get_dirObject



27
28
29
# File 'lib/aina/generable.rb', line 27

def get_dir
  @dir
end

#get_replacementsObject



51
52
53
# File 'lib/aina/generable.rb', line 51

def get_replacements
  @replacements || []
end

#get_templateObject



38
39
40
# File 'lib/aina/generable.rb', line 38

def get_template
  @template
end

#replacements(*replacements) ⇒ Object

Does type template need custom replacements? Then, in type use: replacements %w({replace_this} {and_this_too})



45
46
47
48
49
# File 'lib/aina/generable.rb', line 45

def replacements(*replacements)
  @replacements = %w(name aina_version)
  @replacements += replacements.flatten if replacements
  @replacements = @replacements.map { |r| "{{#{r}}}" }
end

#template(template) ⇒ Object

Does type use a template? Then, in type use: template ‘my-template.php’



34
35
36
# File 'lib/aina/generable.rb', line 34

def template(template)
  @template = "#{Aina::TEMPLATES_DIR}/#{template}" if template
end