Sha256: 441771a4fb618a97a2403f12920d220d2cbeca0acc0bc07e4abd11075e7ac0bd

Contents?: true

Size: 1.94 KB

Versions: 18

Compression:

Stored size: 1.94 KB

Contents

require "ansible_spec/version"
require "ansible_spec/load_ansible"
require "fileutils"

# Reference
# https://github.com/serverspec/serverspec/blob/master/lib/serverspec/setup.rb
# Reference License (MIT)
# https://github.com/serverspec/serverspec/blob/master/LICENSE.txt

module AnsibleSpec

  def self.main()
    safe_create_spec_helper
    safe_create_rakefile
    safe_create_ansiblespec
  end


  def self.safe_create_spec_helper
    content = File.open(File.dirname(__FILE__) + "/../lib/src/spec/spec_helper.rb").read
    safe_mkdir("spec")
    safe_touch("spec/spec_helper.rb")
    File.open("spec/spec_helper.rb", 'w') do |f|
      f.puts content
    end

  end

  def self.safe_create_rakefile
    content = File.open(File.dirname(__FILE__) + "/../lib/src/Rakefile").read
    safe_touch("Rakefile")
    File.open("Rakefile", 'w') do |f|
      f.puts content
    end
  end

  def self.safe_create_ansiblespec
    content = File.open(File.dirname(__FILE__) + "/../lib/src/.ansiblespec").read
    safe_touch(".ansiblespec")
    File.open(".ansiblespec", 'w') do |f|
      f.puts content
    end
  end

  def self.safe_mkdir(dir)
    unless FileTest.exist?("#{dir}")
      FileUtils.mkdir_p("#{dir}")
      TermColor.green
      puts "\t\tcreate\t#{dir}"
      TermColor.reset
    else
      TermColor.red
      puts "\t\texists\t#{dir}"
      TermColor.reset
    end
  end

  def self.safe_touch(file)
    unless File.exists? "#{file}"
      File.open("#{file}", 'w') do |f|
          #f.puts content
      end
      TermColor.green
      puts "\t\tcreate\t#{file}"
      TermColor.reset
    else 
      TermColor.red
      puts "\t\texists\t#{file}"
      TermColor.reset
    end
  end

  class TermColor
    class << self
      # 色を解除
      def reset   ; c 0 ; end 

      # 各色
      def red     ; c 31; end 
      def green   ; c 32; end 

      # カラーシーケンスの出力
      def c(num)
        print "\e[#{num.to_s}m"
      end 
    end 
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ansible_spec-0.2.14 lib/ansible_spec.rb
ansible_spec-0.2.13 lib/ansible_spec.rb
ansible_spec-0.2.12 lib/ansible_spec.rb
ansible_spec-0.2.11 lib/ansible_spec.rb
ansible_spec-0.2.10 lib/ansible_spec.rb
ansible_spec-0.2.9 lib/ansible_spec.rb
ansible_spec-0.2.8 lib/ansible_spec.rb
ansible_spec-0.2.7 lib/ansible_spec.rb
ansible_spec-0.2.7.beta lib/ansible_spec.rb
ansible_spec-0.2.6 lib/ansible_spec.rb
ansible_spec-0.2.5 lib/ansible_spec.rb
ansible_spec-0.2.4 lib/ansible_spec.rb
ansible_spec-0.2.3 lib/ansible_spec.rb
ansible_spec-0.2.2 lib/ansible_spec.rb
ansible_spec-0.2.1 lib/ansible_spec.rb
ansible_spec-0.2 lib/ansible_spec.rb
ansible_spec-0.1.1 lib/ansible_spec.rb
ansible_spec-0.1 lib/ansible_spec.rb