Class: Kamaze::Project::Tools::Gemspec::Writer
- Inherits:
-
BaseTool
- Object
- Observable
- BaseTool
- Kamaze::Project::Tools::Gemspec::Writer
- Defined in:
- lib/kamaze/project/tools/gemspec/writer.rb,
lib/kamaze/project/tools/gemspec.rb
Overview
Class intended to generate gemspec
file from a template
Default template filename is gemspec.tpl
.
Consider to use Dir.chdir
in order read and generate contents
from the right directory (especially during tests).
Defined Under Namespace
Classes: DepGen, Dependency
Instance Attribute Summary collapse
- #observer_peers ⇒ Hash|nil included from Concern::Observable readonly protected
- #project ⇒ Kamaze::Project
-
#templated ⇒ Pathname
Get path (almost filename) to templated gemspec.
Instance Method Summary collapse
-
#content ⇒ String
Get generated/templated content.
-
#context ⇒ Hahsh
Get template's context (variables).
-
#dependency ⇒ Dependency
Get dependency.
-
#deps_gen ⇒ GemspecDepsGen
protected
Get
GemspecDepsGen
instance. -
#generated ⇒ Pathname
Get path (almost filename) to generated gemspec.
- #mutable_attributes ⇒ Object
- #setup ⇒ Object protected
-
#spec_id ⇒ String
Get variable used in template for
Gem::Specification
instantiation. -
#template ⇒ Tenjin::Engine
protected
Get template engine.
-
#to_s ⇒ String
Get string representation.
-
#write ⇒ self
Write gemspec file.
Constructor Details
This class inherits a constructor from Kamaze::Project::Tools::BaseTool
Instance Attribute Details
#observer_peers ⇒ Hash|nil (readonly, protected) Originally defined in module Concern::Observable
#project ⇒ Kamaze::Project
30 31 32 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 30 def project @project end |
#templated ⇒ Pathname
Get path (almost filename) to templated gemspec
39 40 41 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 39 def templated Pathname.new(@templated) end |
Instance Method Details
#content ⇒ String
Get generated/templated content
93 94 95 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 93 def content template.render(templated.to_s, context) end |
#context ⇒ Hahsh
Get template's context (variables)
80 81 82 83 84 85 86 87 88 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 80 def context { name: project.name, version: project.version, dependencies: dependency, }.yield_self do |variables| project.version.to_h.merge(variables) end end |
#dependency ⇒ Dependency
Get dependency
71 72 73 74 75 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 71 def dependency require_relative 'writer/dep_gen' DepGen.new(spec_id).dependency end |
#deps_gen ⇒ GemspecDepsGen (protected)
Get GemspecDepsGen
instance
117 118 119 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 117 def deps_gen GemspecDepsGen.new end |
#generated ⇒ Pathname
Get path (almost filename) to generated gemspec
46 47 48 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 46 def generated Pathname.new("#{project.name}.gemspec") end |
#mutable_attributes ⇒ Object
32 33 34 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 32 def mutable_attributes [:templated, :project] end |
#setup ⇒ Object (protected)
108 109 110 111 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 108 def setup @templated ||= 'gemspec.tpl' @project ||= Kamaze.project end |
#spec_id ⇒ String
Get variable used in template for Gem::Specification
instantiation
61 62 63 64 65 66 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 61 def spec_id templated .read .scan(/Gem::Specification\.new\s+do\s+\|([a-z]+)\|/) .flatten.fetch(0) end |
#template ⇒ Tenjin::Engine (protected)
Get template engine
124 125 126 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 124 def template Tenjin::Engine.new(cache: false) end |
#to_s ⇒ String
Get string representation
54 55 56 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 54 def to_s generated.to_s end |
#write ⇒ self
Write gemspec file
100 101 102 103 104 |
# File 'lib/kamaze/project/tools/gemspec/writer.rb', line 100 def write generated.write(content) self end |