Class: Motion::Util::Generator
- Inherits:
-
Object
- Object
- Motion::Util::Generator
- Defined in:
- lib/motion-util/command/generator.rb
Instance Method Summary collapse
- #context ⇒ Object
- #destination_dir ⇒ Object
- #destination_path ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
- #spec_context ⇒ Object
- #spec_destination_path ⇒ Object
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 |
# File 'lib/motion-util/command/generator.rb', line 7 def initialize d = File.dirname(__FILE__).split("/")[0..-4] d << "template" @project_path = Dir.pwd @template_dir = File.join d end |
Instance Method Details
#context ⇒ Object
39 40 41 42 43 |
# File 'lib/motion-util/command/generator.rb', line 39 def context c = File.read File.join(@template_dir, "class", file_type + ".rb") c.gsub! /#\{class_name\}/, objc_class_name c end |
#destination_dir ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/motion-util/command/generator.rb', line 14 def destination_dir case file_type.to_s when "general" "app" when /controller/ "app/controller" else "app/#{file_type}" end end |
#destination_path ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/motion-util/command/generator.rb', line 25 def destination_path case file_type when /controller/, /view/ "#{destination_dir}/#{class_file_name}_#{file_type}.rb" else "#{destination_dir}/#{class_file_name}.rb" end end |
#run ⇒ Object
53 54 55 56 |
# File 'lib/motion-util/command/generator.rb', line 53 def run make_file make_spec_file end |
#spec_context ⇒ Object
45 46 47 48 49 50 |
# File 'lib/motion-util/command/generator.rb', line 45 def spec_context c = File.read File.join(@template_dir, "spec", "spec.rb") c.gsub! /#\{class_name\}/, objc_class_name c.gsub! /#\{camelized_file_type\}/, camelized_file_type c end |
#spec_destination_path ⇒ Object
34 35 36 37 |
# File 'lib/motion-util/command/generator.rb', line 34 def spec_destination_path d = destination_path.gsub /^app/, "spec" d.gsub /\.rb$/, "_spec.rb" end |