Module: Hen::CLI
- Included in:
- Commands
- Defined in:
- lib/hen/cli.rb
Overview
Some helper methods used by the Hen executable. Also available for use in custom project skeletons.
Class Attribute Summary collapse
-
.answers ⇒ Object
readonly
Collect user’s answers by key, so we don’t have to ask again.
Instance Method Summary collapse
-
#classname(default = default_classname) ⇒ Object
The project’s namespace.
-
#emailaddress(default = default_emailaddress) ⇒ Object
The author’s e-mail address.
-
#fullname(default = default_fullname) ⇒ Object
The author’s full name.
-
#githubuser(default = default_githubuser) ⇒ Object
The author’s GitHub user name.
-
#progdesc(default = nil) ⇒ Object
A long description of the project.
-
#progname(default = nil) ⇒ Object
The project name.
-
#progsumm(default = nil) ⇒ Object
A short summary of the project’s description.
-
#render(sample, target) ⇒ Object
Renders the contents of
sampleas an ERb template, storing the result intarget.
Class Attribute Details
.answers ⇒ Object (readonly)
Collect user’s answers by key, so we don’t have to ask again.
47 48 49 |
# File 'lib/hen/cli.rb', line 47 def answers @answers end |
Instance Method Details
#classname(default = default_classname) ⇒ Object
The project’s namespace. (Required)
Namespaces SHOULD match the project name in SnakeCase.
95 96 97 |
# File 'lib/hen/cli.rb', line 95 def classname(default = default_classname) ask!("Module's/Class's name", default) end |
#emailaddress(default = default_emailaddress) ⇒ Object
The author’s e-mail address. (Optional, but highly recommended)
105 106 107 |
# File 'lib/hen/cli.rb', line 105 def emailaddress(default = default_emailaddress) ask('E-mail address', default) end |
#fullname(default = default_fullname) ⇒ Object
The author’s full name. (Required)
100 101 102 |
# File 'lib/hen/cli.rb', line 100 def fullname(default = default_fullname) ask!('Full name', default) end |
#githubuser(default = default_githubuser) ⇒ Object
The author’s GitHub user name. (Optional)
110 111 112 |
# File 'lib/hen/cli.rb', line 110 def githubuser(default = default_githubuser) ask('GitHub user name', default) end |
#progdesc(default = nil) ⇒ Object
A long description of the project. (Optional)
88 89 90 |
# File 'lib/hen/cli.rb', line 88 def progdesc(default = nil) ask("Program's full description", default) end |
#progname(default = nil) ⇒ Object
The project name. (Required)
Quoting the Ruby Packaging Standard:
Project names SHOULD only contain underscores as separators in their names.
If a project is an enhancement, plugin, extension, etc. for some other project it SHOULD contain a dash in the name between the original name and the project’s name.
78 79 80 |
# File 'lib/hen/cli.rb', line 78 def progname(default = nil) ask!("Project's name", default) end |
#progsumm(default = nil) ⇒ Object
A short summary of the project’s description. (Required)
83 84 85 |
# File 'lib/hen/cli.rb', line 83 def progsumm(default = nil) ask!("Program's description summary", default) end |
#render(sample, target) ⇒ Object
Renders the contents of sample as an ERb template, storing the result in target. Returns the content.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hen/cli.rb', line 53 def render(sample, target) abort "Sample file not found: #{sample}" unless File.readable?(sample) if File.readable?(target) abort unless agree("Target file already exists: #{target}. Overwrite? ") File.rename(target, "#{target}.bak-#{Time.now.to_i}") end content = ERB.new(File.read(sample)).result(binding) File.open(target, 'w') { |f| f.puts content unless content.empty? } content end |