Class: LapisLazuli::Generators::Cucumber

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/lapis_lazuli/generators/cucumber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_email(cuke) ⇒ Object



123
124
125
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 123

def self.get_email(cuke)
  run_helper(cuke, 'git config --get user.email', '[email protected]')
end

.get_username(cuke) ⇒ Object



117
118
119
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 117

def self.get_username(cuke)
  run_helper(cuke, 'git config --get user.name', 'spriteCloud B.V.')
end

.run_helper(cuke, command, default) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 107

def self.run_helper(cuke, command, default)
  begin
    cuke.run(command, {:capture => true}).strip || default
  rescue
    default
  end
end

.source_rootObject



101
102
103
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 101

def self.source_root
  File.join(File.dirname(__FILE__), "cucumber", "template")
end

Instance Method Details

#copy_templateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 53

def copy_template
  opts = {
    :year => Time.now.year,
    :user => Cucumber.get_username(self),
    :email => Cucumber.get_email(self),
    :lapis_lazuli => {
      :version => LapisLazuli::VERSION,
      :dependency => '"' + LapisLazuli::VERSION + '"',
    },
    :project => {
      :name => File.basename(path),
    },
  }

  # If a branch was specified on the CLI, we have to update the dependency
  # string.
  if options.has_key?("branch")
    opts[:lapis_lazuli][:dependency] = ":github => 'spriteCloud/lapis-lazuli', :branch => '#{options["branch"]}'"
  end

  require 'facets/string/lchomp'
  require 'find'
  Find.find(Cucumber.source_root) do |name|
    # Skip the source root itself
    next if name == Cucumber.source_root

    # Find the relative path and file name component
    relative = name.lchomp(Cucumber.source_root + File::SEPARATOR)
    filename = File.basename(relative)

    # Ignore hidden files UNLESS they're listed in the allowed hidden
    # files.
    if filename.start_with?('.')
      next if not ALLOWED_HIDDEN.include?(filename)
    end

    # Create directories as empty directories, and treat every file as 
    # a template.
    if File.directory?(name)
      empty_directory(File.join(path, relative))
    else
      template(relative, File.join(path, relative), opts)
    end
  end
end

#create_directory_structureObject



44
45
46
47
48
49
# File 'lib/lapis_lazuli/generators/cucumber.rb', line 44

def create_directory_structure
  empty_directory(path)
  PROJECT_PATHS.each do |p|
    empty_directory(File.join(path, p))
  end
end