Module: RoCommands::Generators::BaseGenerator::ClassMethods

Included in:
RailsGenerator::ClassMethods
Defined in:
lib/ro_commands/generators/base_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

Returns the value of attribute file.



57
58
59
# File 'lib/ro_commands/generators/base_generator.rb', line 57

def file
  @file
end

Instance Method Details

#create(*args) ⇒ Object



77
78
79
80
# File 'lib/ro_commands/generators/base_generator.rb', line 77

def create(*args)
  reset
  template
end

#created_fileObject



49
50
51
# File 'lib/ro_commands/generators/base_generator.rb', line 49

def created_file
  @created_file ||= lastest_file
end

#ctnObject



53
54
55
# File 'lib/ro_commands/generators/base_generator.rb', line 53

def ctn
  @ctn ||= ""
end

#file_nameObject



82
83
84
# File 'lib/ro_commands/generators/base_generator.rb', line 82

def file_name
  @file_name ||= ""
end

#file_write(path) ⇒ Object



26
27
28
29
# File 'lib/ro_commands/generators/base_generator.rb', line 26

def file_write(path)
  dir = File.dirname(path)
  RoFile.write(path, ctn)
end

#lastest_fileObject



37
38
39
40
41
42
43
# File 'lib/ro_commands/generators/base_generator.rb', line 37

def lastest_file
  Find.find(Dir.pwd, dir).select do |f|
    test(?f, f)
  end.sort_by do |f|
    Time.at(File.ctime(f).to_f)
  end.last
end

#lib_pathObject



31
32
33
34
35
# File 'lib/ro_commands/generators/base_generator.rb', line 31

def lib_path
  name.split("::").map do |i|
    i.downcase
  end.join("/")
end

#openObject



45
46
47
# File 'lib/ro_commands/generators/base_generator.rb', line 45

def open
  bash "#{::RoDefault.editor} #{created_file}"
end

#pathObject



63
64
65
# File 'lib/ro_commands/generators/base_generator.rb', line 63

def path
  File.join(dir, file)
end

#resetObject



86
87
88
89
90
# File 'lib/ro_commands/generators/base_generator.rb', line 86

def reset
  instance_variables.each do |iv|
    instance_variable_set iv, nil
  end
end

#templateObject



71
72
73
74
75
# File 'lib/ro_commands/generators/base_generator.rb', line 71

def template
  ctn = RoFile.read File.expand_path("../templates/#{dir}.erb", __FILE__)
  @ctn = ERB.new(ctn).result(binding)
  to
end

#toObject



67
68
69
# File 'lib/ro_commands/generators/base_generator.rb', line 67

def to
  Out.out "writing to #{path}"
end