Class: PreCommit::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/pre-commit/template.rb

Constant Summary collapse

TEMPLATE_DIR =
File.expand_path("../../../templates/gem", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Template

Returns a new instance of Template.



11
12
13
14
15
16
# File 'lib/pre-commit/template.rb', line 11

def initialize(*args)
  @name, @author, @email, @description = args
  @gem_name    = "pre-commit-#{name}"
  @copyright   = "#{Date.today.year} #{author} #{email}"
  validate_params
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def author
  @author
end

Returns the value of attribute copyright.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def copyright
  @copyright
end

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def description
  @description
end

#emailObject (readonly)

Returns the value of attribute email.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def email
  @email
end

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def gem_name
  @gem_name
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/pre-commit/template.rb', line 9

def name
  @name
end

Instance Method Details

#all_filesObject



31
32
33
34
# File 'lib/pre-commit/template.rb', line 31

def all_files
  Dir.glob("#{TEMPLATE_DIR}/**/*", File::FNM_DOTMATCH)
    .reject { |path| File.directory?(path) }
end

#saveObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pre-commit/template.rb', line 18

def save
  puts "Generating #{gem_name}"
  all_files.each{|file| parse_and_save(file) }
  initialize_git
  puts <<-STEPS

Next steps:
- write your checks and tests for them
- push code to github
- open a ticket to merge your project: https://github.com/jish/pre-commit/issues
STEPS
end

#target_path(file) ⇒ Object



36
37
38
39
40
41
# File 'lib/pre-commit/template.rb', line 36

def target_path(file)
  file
    .sub(TEMPLATE_DIR, gem_name)
    .sub("GEM_NAME", gem_name)
    .sub("PLUGIN_NAME", name)
end