Class: Generable::Base
- Inherits:
-
Object
- Object
- Generable::Base
- Extended by:
- Generable
- Defined in:
- lib/aina/generable/base.rb
Overview
Generable class
Instance Attribute Summary collapse
-
#aina_version ⇒ Object
readonly
Returns the value of attribute aina_version.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#supports ⇒ Object
readonly
Returns the value of attribute supports.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #after_generate ⇒ Object
- #destroy ⇒ Object
- #dir ⇒ Object
- #display_name ⇒ Object
- #generate ⇒ Object
-
#initialize(name, options = nil) ⇒ Base
constructor
A new instance of Base.
- #replacements ⇒ Object
- #set_custom_vars ⇒ Object
Methods included from Generable
accepts?, class_name_for, generable_types, get_after_generate, get_dir, get_replacements, get_template
Constructor Details
#initialize(name, options = nil) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/aina/generable/base.rb', line 6 def initialize(name, =nil) @original_name = format_name(name) @options = @aina_version = Aina::VERSION @template = self.template @dir = self.dir @file = generate_file_name set_custom_vars end |
Instance Attribute Details
#aina_version ⇒ Object (readonly)
Returns the value of attribute aina_version.
4 5 6 |
# File 'lib/aina/generable/base.rb', line 4 def aina_version @aina_version end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/aina/generable/base.rb', line 4 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/aina/generable/base.rb', line 4 def name @name end |
#supports ⇒ Object (readonly)
Returns the value of attribute supports.
4 5 6 |
# File 'lib/aina/generable/base.rb', line 4 def supports @supports end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/aina/generable/base.rb', line 4 def template @template end |
Instance Method Details
#after_generate ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/aina/generable/base.rb', line 56 def after_generate if self.class.get_after_generate self.class.get_after_generate.each do |callback| self.send(callback) end end end |
#destroy ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/aina/generable/base.rb', line 64 def destroy if File.exists?(@file) File.delete(@file) else raise "No #{self.class} with name #{@name}" end end |
#dir ⇒ Object
33 34 35 |
# File 'lib/aina/generable/base.rb', line 33 def dir self.class.get_dir end |
#display_name ⇒ Object
17 18 19 20 21 22 |
# File 'lib/aina/generable/base.rb', line 17 def display_name name .split('_') .each {|w| w.capitalize! } .join(' ') end |
#generate ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/aina/generable/base.rb', line 45 def generate text = File.read(@template) replacements.each do |replace| attribute = replace.gsub(/[{}]/, '') text.gsub!(/#{replace}/, self.send(attribute)) end File.open(@file, "w") {|file| file.puts text} after_generate end |
#replacements ⇒ Object
41 42 43 |
# File 'lib/aina/generable/base.rb', line 41 def replacements self.class.get_replacements end |
#set_custom_vars ⇒ Object
28 29 30 31 |
# File 'lib/aina/generable/base.rb', line 28 def set_custom_vars # Nothing here # This can be used in types to parse required instance variables end |