Class: BoringBuilder::Initializer
- Inherits:
-
Object
- Object
- BoringBuilder::Initializer
- Defined in:
- lib/boringbuilder/initializer.rb
Constant Summary collapse
- TEMPLATES =
%i[auto ruby node rust go generic].freeze
Instance Attribute Summary collapse
-
#requested_template ⇒ Object
readonly
Returns the value of attribute requested_template.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #call(force: false) ⇒ Object
-
#initialize(root, template: :auto) ⇒ Initializer
constructor
A new instance of Initializer.
- #template_name ⇒ Object
Constructor Details
#initialize(root, template: :auto) ⇒ Initializer
Returns a new instance of Initializer.
12 13 14 15 |
# File 'lib/boringbuilder/initializer.rb', line 12 def initialize(root, template: :auto) @root = Pathname.new(root). @requested_template = template.to_s.downcase.to_sym end |
Instance Attribute Details
#requested_template ⇒ Object (readonly)
Returns the value of attribute requested_template.
10 11 12 |
# File 'lib/boringbuilder/initializer.rb', line 10 def requested_template @requested_template end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/boringbuilder/initializer.rb', line 10 def root @root end |
Instance Method Details
#call(force: false) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/boringbuilder/initializer.rb', line 17 def call(force: false) validate! raise ConfigurationError, "#{path} already exists; pass --force to replace it" if path.exist? && !force FileUtils.mkdir_p(path.dirname) path.write(template) path end |
#template_name ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/boringbuilder/initializer.rb', line 26 def template_name return requested_template unless requested_template == :auto return :ruby if root.join("Gemfile").file? return :node if root.join("package.json").file? return :rust if root.join("Cargo.toml").file? return :go if root.join("go.mod").file? :generic end |