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

#file ⇒ Object

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_file ⇒ Object



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

def created_file
  @created_file ||= lastest_file
end

#ctn ⇒ Object



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

def ctn
  @ctn ||= ""
end

#file_name ⇒ Object



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_file ⇒ Object



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_path ⇒ Object



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

#open ⇒ Object



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

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

#path ⇒ Object



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

def path
  File.join(dir, file)
end

#reset ⇒ Object



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

#template ⇒ Object



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

#to ⇒ Object



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

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