Sha256: 9dcc9478ef94b432bc126957149ef2e2295470df91ce7b2de0c7915faa809f63

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require "fileutils"

module RoCommands
  module Generators
    module BaseGenerator

      class << self
        def included(base)
          base.extend(ClsMeths)
        end
      end

      module ClsMeths
        def bash(*cmds)
          Kernel.system(cmds.flatten.join(" && "))
        end

        def file_write(path)
          dir = File.dirname(path)
          FileUtils.mkpath dir
          puts "writing #{path}"
          File.write(path, ctn)
        end

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

        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

        def open
          bash "rubymine #{created_file}"
        end

        def created_file
          @created_file ||= lastest_file
        end

        def ctn
          @ctn ||= ""
        end

        def path
          File.join(dir, file)
        end

        def to
          puts "writing to #{path}"
        end

        def tt(name)
          puts "creating #{path}"
          ctn = File.read File.expand_path("../templates/#{dir}.erb", __FILE__)
          @ctn = ERB.new(ctn).result(binding)
          to
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ro_commands-0.0.3 lib/ro_commands/generators/base_generator.rb
ro_commands-0.0.2 lib/ro_commands/generators/base_generator.rb
ro_commands-0.0.1 lib/ro_commands/generators/base_generator.rb