Sha256: eb61f58779809249b0b5d7d61a924237975566468525d6b8e4ea9e0c0ce40347

Contents?: true

Size: 1.84 KB

Versions: 240

Compression:

Stored size: 1.84 KB

Contents

# This code is borrowed shamelessly from Bourbon

require 'smock/version'
require "fileutils"
require 'thor'

module Smock
  class Generator < Thor
    map ['-v', '--version'] => :versions

    desc 'install', 'Install Smock into your project'
    method_options :path => :string, :force => :boolean
    def install
      if smock_files_already_exist? && !options[:force]
        puts "Smock files already installed, doing nothing."
      else
        install_files
        puts "Smock files installed to #{install_path}/"
      end
    end

    desc 'update', 'Update Smock'
    method_options :path => :string
    def update
      if smock_files_already_exist?
        remove_smock_directory
        install_files
        puts "Smock files updated."
      else
        puts "No existing Smock installation. Doing nothing."
      end
    end

    desc 'version', 'Show Smock version'
    def version
      say "Smock #{Smock::VERSION}"
    end

    private

    def smock_files_already_exist?
      install_path.exist?
    end

    def install_path
      @install_path ||= if options[:path]
                          Pathname.new(File.join(options[:path], 'smock'))
                        else
                          Pathname.new('smock')
                        end
    end

    def install_files
      make_install_directory
      copy_in_scss_files
    end

    def remove_smock_directory
      FileUtils.rm_rf("smock")
    end

    def make_install_directory
      FileUtils.mkdir_p(install_path)
    end

    def copy_in_scss_files
      FileUtils.cp_r(all_stylesheets, install_path)
    end

    def all_stylesheets
      Dir["#{stylesheets_directory}/*"]
    end

    def stylesheets_directory
      File.join(top_level_directory, "app", "assets", "stylesheets")
    end

    def top_level_directory
      File.dirname(File.dirname(File.dirname(__FILE__)))
    end
  end
end

Version data entries

240 entries across 240 versions & 1 rubygems

Version Path
smock-0.1.246 lib/smock/generator.rb
smock-0.1.245 lib/smock/generator.rb
smock-0.1.244 lib/smock/generator.rb
smock-0.1.243 lib/smock/generator.rb
smock-0.1.242 lib/smock/generator.rb
smock-0.1.241 lib/smock/generator.rb
smock-0.1.240 lib/smock/generator.rb
smock-0.1.239 lib/smock/generator.rb
smock-0.1.2 lib/smock/generator.rb
smock-0.1.1 lib/smock/generator.rb
smock-0.1.238 lib/smock/generator.rb
smock-0.1.237 lib/smock/generator.rb
smock-0.1.236 lib/smock/generator.rb
smock-0.1.235 lib/smock/generator.rb
smock-0.1.234 lib/smock/generator.rb
smock-0.1.233 lib/smock/generator.rb
smock-0.1.232 lib/smock/generator.rb
smock-0.1.231 lib/smock/generator.rb
smock-0.1.230 lib/smock/generator.rb
smock-0.1.229 lib/smock/generator.rb