Class: Motion::Util::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-util/command/generator.rb

Instance Method Summary collapse

Constructor Details

#initializeGenerator

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

#contextObject



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_dirObject



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_pathObject



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

#runObject



53
54
55
56
# File 'lib/motion-util/command/generator.rb', line 53

def run
  make_file
  make_spec_file
end

#spec_contextObject



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_pathObject



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