Class: Kamaze::Project::Tools::Gemspec::Packer::Command
- Includes:
- Concern::Cli::WithExitOnFailure, Concern::Sh
- Defined in:
- lib/kamaze/project/tools/gemspec/packer/command.rb
Overview
Build/pack a buildable
Command is able to execute itself.
Command depends on FileUtils::sh
provided by rake
.
During execution, command chdir
to src_dir
.
Defined Under Namespace
Classes: InitializationError
Instance Attribute Summary collapse
-
#bin_dir ⇒ Pathname
Get path to "compiled" input file.
-
#executable ⇒ Pathname
Executable used by command.
-
#packable ⇒ Object
Filepath to the product issued by command.
- #pwd ⇒ Pathname readonly
-
#src_dir ⇒ Object
The path to source files.
-
#tmp_dir ⇒ Object
The directory for temporary files.
Instance Method Summary collapse
-
#create_shell_runner(cmd) ⇒ Proc
included
from Concern::Sh
protected
Get shell block.
-
#debug_cmd(cmd) ⇒ String
included
from Concern::Sh
protected
Print a debug message.
- #execute ⇒ Object
-
#failure? ⇒ Boolean
(also: #failed?)
included
from Concern::Cli
Denote execution is a failure.
-
#initialize {|_self| ... } ⇒ Command
constructor
A new instance of Command.
-
#preserved_env(from = ENV) ⇒ Hash
protected
Get preserved env (from given env).
-
#process_attrs ⇒ Object
protected
Process attributes.
-
#retcode ⇒ Fixnum
included
from Concern::Cli
Status code usable to eventually initiates the termination.
-
#sh(*cmd, &block) ⇒ Object
included
from Concern::Sh
protected
Run given (
cmd
) system command. -
#shell_runner_debug? ⇒ Boolean
included
from Concern::Sh
Denote shell runner is in debug mode.
-
#success? ⇒ Boolean
(also: #successful?)
included
from Concern::Cli
Denote execution is a success.
- #to_a ⇒ Array<String>
-
#with_exit_on_failure {|Object| ... } ⇒ Object
included
from Concern::Cli::WithExitOnFailure
protected
Initiates termination by raising
SystemExit
exception depending onsuccess
of given block.
Constructor Details
#initialize {|_self| ... } ⇒ Command
Returns a new instance of Command.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 52 def initialize yield self @executable ||= :rubyc @pwd = ::Pathname.new(Dir.pwd) [:executable, :packable, :tmp_dir, :bin_dir].each do |m| self.singleton_class.class_eval { protected "#{m}=" } next unless self.__send__(m).nil? raise InitializationError, "#{m} must be set, got nil" end end |
Instance Attribute Details
#bin_dir ⇒ Pathname
Get path to "compiled" input file
SHOULD like to bin
as seen in gemspec bindir
79 80 81 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 79 def bin_dir ::Pathname.new(@bin_dir) end |
#executable ⇒ Pathname
Executable used by command
70 71 72 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 70 def executable ::Pathname.new(Cliver.detect!(@executable)).freeze end |
#packable ⇒ Object
Filepath to the product issued by command
32 33 34 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 32 def packable @packable end |
#pwd ⇒ Pathname (readonly)
46 47 48 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 46 def pwd @pwd end |
#src_dir ⇒ Object
The path to source files
43 44 45 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 43 def src_dir @src_dir end |
#tmp_dir ⇒ Object
The directory for temporary files
35 36 37 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 35 def tmp_dir @tmp_dir end |
Instance Method Details
#create_shell_runner(cmd) ⇒ Proc (protected) Originally defined in module Concern::Sh
Get shell block
#debug_cmd(cmd) ⇒ String (protected) Originally defined in module Concern::Sh
Print a debug message
#execute ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 94 def execute env = preserved_env Dir.chdir(pwd.join(src_dir)) do with_exit_on_failure do Bundler.with_clean_env do sh(*[env].concat(self.to_a)) self.retcode = self.shell_runner_last_status.exitstatus end end end end |
#failure? ⇒ Boolean Also known as: failed? Originally defined in module Concern::Cli
Denote execution is a failure.
#preserved_env(from = ENV) ⇒ Hash (protected)
refactor
Get preserved env (from given env)
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 131 def preserved_env(from = ENV) env = {} from = from.to_h ['CPPFLAGS'].each do |key| next unless from.key?(key) env[key] = from.fetch(key) end env end |
#process_attrs ⇒ Object (protected)
Process attributes
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 113 def process_attrs [:executable, :packable, :tmp_dir, :bin_dir].each do |m| self.singleton_class.class_eval { protected "#{m}=" } if self.__send__(m).nil? raise InitializationError, "#{m} must be set, got nil" end end self end |
#retcode ⇒ Fixnum Originally defined in module Concern::Cli
Status code usable to eventually initiates the termination.
#sh(*cmd, &block) ⇒ Object (protected) Originally defined in module Concern::Sh
Run given (cmd
) system command.
If multiple arguments are given the command is run directly (without the shell, same semantics as Kernel::exec and Kernel::system).
#shell_runner_debug? ⇒ Boolean Originally defined in module Concern::Sh
Denote shell runner is in debug mode.
#success? ⇒ Boolean Also known as: successful? Originally defined in module Concern::Cli
Denote execution is a success.
#to_a ⇒ Array<String>
84 85 86 87 88 89 90 91 92 |
# File 'lib/kamaze/project/tools/gemspec/packer/command.rb', line 84 def to_a packable = ::Pathname.new(self.packable) [executable, bin_dir.join(packable.basename), '-r', '.', '-d', pwd.join(tmp_dir), '-o', pwd.join(packable)].map(&:to_s) end |
#with_exit_on_failure {|Object| ... } ⇒ Object (protected) Originally defined in module Concern::Cli::WithExitOnFailure
Initiates termination by raising SystemExit
exception
depending on success
of given block.