Class: Pandocomatic::Command
- Inherits:
-
Object
- Object
- Pandocomatic::Command
- Defined in:
- lib/pandocomatic/command/command.rb
Overview
Command is a base class of all actions pandocomatic executes while converting a file or a directory of files.
Direct Known Subclasses
ConvertFileCommand, ConvertListCommand, CopyFileCommand, CreateLinkCommand, SkipCommand
Constant Summary collapse
- @@total =
rubocop:disable Style/ClassVars
0- @@dry_run =
false- @@quiet =
false- @@debug =
false- @@src_root =
'.'- @@modified_only =
false
Instance Attribute Summary collapse
-
#errors ⇒ Error[]
List of errors created while preparing and running a command.
-
#index ⇒ Number
The index of this Command in the list with all commands to run when running pandocomatic.
Class Method Summary collapse
-
.reset(configuration) ⇒ Object
Reset all Commands.
Instance Method Summary collapse
-
#all_errors ⇒ Error[]
Get all the errors generated while executing this Command.
-
#count ⇒ Number
The number of commands executed by this Command; a Command can have sub commands as well.
-
#debug? ⇒ Boolean
Is this Command executed in debug mode?.
-
#directory? ⇒ Boolean
Is this Command converting a directory?.
-
#dry_run? ⇒ Boolean
Does this Command not actually execute?.
-
#errors? ⇒ Error[]
Has this Command run in any errors?.
-
#execute ⇒ Object
Execute this Command.
-
#file_modified?(src, dst) ⇒ Boolean
Is the source file newer than the destination file?.
-
#index_to_s ⇒ String
Convert this Command’s index to a string representation.
-
#initialize ⇒ Command
constructor
Create a new Command.
-
#make_quiet ⇒ Object
Make this Command run quietly.
-
#modified_only? ⇒ Boolean
Is this Command only executed on modified files?.
-
#multiple? ⇒ Boolean
Does this Command convert a file multiple times?.
-
#quiet? ⇒ Boolean
Is this Command executed silently?.
-
#run ⇒ Object
Actually run this Command.
-
#runnable? ⇒ Boolean
Are there any errors while configuring this Command? If not, this Command is runnable.
-
#skip? ⇒ Boolean
Will this Command be skipped, thus not executed?.
-
#src_root ⇒ String
Get the root directory of this Command’s conversion process.
-
#to_s ⇒ String
Create a String representation of this Command.
-
#uncount ⇒ Object
Decrement the total number of conversion commands by 1.
Constructor Details
#initialize ⇒ Command
Create a new Command
47 48 49 50 51 |
# File 'lib/pandocomatic/command/command.rb', line 47 def initialize @errors = [] @@total += 1 @index = @@total end |
Instance Attribute Details
#errors ⇒ Error[]
Returns list of errors created while preparing and running a command.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/pandocomatic/command/command.rb', line 34 class Command attr_reader :errors, :index # rubocop:disable Style/ClassVars @@total = 0 @@dry_run = false @@quiet = false @@debug = false @@src_root = '.' @@modified_only = false # Create a new Command def initialize @errors = [] @@total += 1 @index = @@total end # Reset all Commands # # @param configuration [Configuration] the configuration used to convert def self.reset(configuration) @@src_root = configuration.src_root @@dry_run = configuration.dry_run? @@quiet = configuration.quiet? @@debug = configuration.debug? @@modified_only = configuration.modified_only? @@total = 0 end # Get the root directory of this Command's conversion process # # @return [String] def src_root @@src_root end # Does this Command not actually execute? # # @return [Boolean] def dry_run? @@dry_run end # Is this Command executed silently? # # @return [Boolean] def quiet? @@quiet end # Is this Command executed in debug mode? # # @return [Boolean] def debug? @@debug end # Is this Command only executed on modified files? # # @return [Boolean] def modified_only? @@modified_only end # The number of commands executed by this Command; a Command can have sub # commands as well. # # @return [Number] def count 1 end # Get all the errors generated while executing this Command # # @return [Error[]] def all_errors @errors end # Make this Command run quietly def make_quiet @@quiet = true end # Convert this Command's index to a string representation # # @return [String] def index_to_s (@@total - @index + 1).to_s.rjust(@@total.to_s.size) end # Execute this Command. A Command can be dry-run as well, in which it is # not actually run. def execute CommandPrinter.new(self).print unless quiet? run if !dry_run? && runnable? end # Actually run this Command def run; end # Are there any errors while configuring this Command? If not, this # Command is runnable. # # @return [Boolean] def runnable? !errors? end # Create a String representation of this Command # # @return [String] def to_s 'command' end # Is this Command converting a directory? # # @return [Boolean] false def directory? false end # Does this Command convert a file multiple times? # # @return [Boolean] false def multiple? false end # Will this Command be skipped, thus not executed? # # @return [Boolean] false def skip? false end # Decrement the total number of conversion commands by 1 def uncount @@total -= 1 end # rubocop:enable Style/ClassVars # Has this Command run in any errors? # # @return [Error[]] def errors? !@errors.empty? end # Is the source file newer than the destination file? # # @param src [String] the source file # @param dst [String] the destination file # # @return [Boolean] True if src has been modified after dst has been last def file_modified?(src, dst) !File.exist? dst or File.mtime(src) > File.mtime(dst) end end |
#index ⇒ Number
Returns the index of this Command in the list with all commands to run when running pandocomatic.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/pandocomatic/command/command.rb', line 34 class Command attr_reader :errors, :index # rubocop:disable Style/ClassVars @@total = 0 @@dry_run = false @@quiet = false @@debug = false @@src_root = '.' @@modified_only = false # Create a new Command def initialize @errors = [] @@total += 1 @index = @@total end # Reset all Commands # # @param configuration [Configuration] the configuration used to convert def self.reset(configuration) @@src_root = configuration.src_root @@dry_run = configuration.dry_run? @@quiet = configuration.quiet? @@debug = configuration.debug? @@modified_only = configuration.modified_only? @@total = 0 end # Get the root directory of this Command's conversion process # # @return [String] def src_root @@src_root end # Does this Command not actually execute? # # @return [Boolean] def dry_run? @@dry_run end # Is this Command executed silently? # # @return [Boolean] def quiet? @@quiet end # Is this Command executed in debug mode? # # @return [Boolean] def debug? @@debug end # Is this Command only executed on modified files? # # @return [Boolean] def modified_only? @@modified_only end # The number of commands executed by this Command; a Command can have sub # commands as well. # # @return [Number] def count 1 end # Get all the errors generated while executing this Command # # @return [Error[]] def all_errors @errors end # Make this Command run quietly def make_quiet @@quiet = true end # Convert this Command's index to a string representation # # @return [String] def index_to_s (@@total - @index + 1).to_s.rjust(@@total.to_s.size) end # Execute this Command. A Command can be dry-run as well, in which it is # not actually run. def execute CommandPrinter.new(self).print unless quiet? run if !dry_run? && runnable? end # Actually run this Command def run; end # Are there any errors while configuring this Command? If not, this # Command is runnable. # # @return [Boolean] def runnable? !errors? end # Create a String representation of this Command # # @return [String] def to_s 'command' end # Is this Command converting a directory? # # @return [Boolean] false def directory? false end # Does this Command convert a file multiple times? # # @return [Boolean] false def multiple? false end # Will this Command be skipped, thus not executed? # # @return [Boolean] false def skip? false end # Decrement the total number of conversion commands by 1 def uncount @@total -= 1 end # rubocop:enable Style/ClassVars # Has this Command run in any errors? # # @return [Error[]] def errors? !@errors.empty? end # Is the source file newer than the destination file? # # @param src [String] the source file # @param dst [String] the destination file # # @return [Boolean] True if src has been modified after dst has been last def file_modified?(src, dst) !File.exist? dst or File.mtime(src) > File.mtime(dst) end end |
Class Method Details
.reset(configuration) ⇒ Object
Reset all Commands
56 57 58 59 60 61 62 63 |
# File 'lib/pandocomatic/command/command.rb', line 56 def self.reset(configuration) @@src_root = configuration.src_root @@dry_run = configuration.dry_run? @@quiet = configuration.quiet? @@debug = configuration.debug? @@modified_only = configuration.modified_only? @@total = 0 end |
Instance Method Details
#all_errors ⇒ Error[]
Get all the errors generated while executing this Command
111 112 113 |
# File 'lib/pandocomatic/command/command.rb', line 111 def all_errors @errors end |
#count ⇒ Number
The number of commands executed by this Command; a Command can have sub commands as well.
104 105 106 |
# File 'lib/pandocomatic/command/command.rb', line 104 def count 1 end |
#debug? ⇒ Boolean
Is this Command executed in debug mode?
89 90 91 |
# File 'lib/pandocomatic/command/command.rb', line 89 def debug? @@debug end |
#directory? ⇒ Boolean
Is this Command converting a directory?
155 156 157 |
# File 'lib/pandocomatic/command/command.rb', line 155 def directory? false end |
#dry_run? ⇒ Boolean
Does this Command not actually execute?
75 76 77 |
# File 'lib/pandocomatic/command/command.rb', line 75 def dry_run? @@dry_run end |
#errors? ⇒ Error[]
Has this Command run in any errors?
183 184 185 |
# File 'lib/pandocomatic/command/command.rb', line 183 def errors? !@errors.empty? end |
#execute ⇒ Object
Execute this Command. A Command can be dry-run as well, in which it is not actually run.
129 130 131 132 |
# File 'lib/pandocomatic/command/command.rb', line 129 def execute CommandPrinter.new(self).print unless quiet? run if !dry_run? && runnable? end |
#file_modified?(src, dst) ⇒ Boolean
Is the source file newer than the destination file?
193 194 195 |
# File 'lib/pandocomatic/command/command.rb', line 193 def file_modified?(src, dst) !File.exist? dst or File.mtime(src) > File.mtime(dst) end |
#index_to_s ⇒ String
Convert this Command’s index to a string representation
123 124 125 |
# File 'lib/pandocomatic/command/command.rb', line 123 def index_to_s (@@total - @index + 1).to_s.rjust(@@total.to_s.size) end |
#make_quiet ⇒ Object
Make this Command run quietly
116 117 118 |
# File 'lib/pandocomatic/command/command.rb', line 116 def make_quiet @@quiet = true end |
#modified_only? ⇒ Boolean
Is this Command only executed on modified files?
96 97 98 |
# File 'lib/pandocomatic/command/command.rb', line 96 def modified_only? @@modified_only end |
#multiple? ⇒ Boolean
Does this Command convert a file multiple times?
162 163 164 |
# File 'lib/pandocomatic/command/command.rb', line 162 def multiple? false end |
#quiet? ⇒ Boolean
Is this Command executed silently?
82 83 84 |
# File 'lib/pandocomatic/command/command.rb', line 82 def quiet? @@quiet end |
#run ⇒ Object
Actually run this Command
135 |
# File 'lib/pandocomatic/command/command.rb', line 135 def run; end |
#runnable? ⇒ Boolean
Are there any errors while configuring this Command? If not, this Command is runnable.
141 142 143 |
# File 'lib/pandocomatic/command/command.rb', line 141 def runnable? !errors? end |
#skip? ⇒ Boolean
Will this Command be skipped, thus not executed?
169 170 171 |
# File 'lib/pandocomatic/command/command.rb', line 169 def skip? false end |
#src_root ⇒ String
Get the root directory of this Command’s conversion process
68 69 70 |
# File 'lib/pandocomatic/command/command.rb', line 68 def src_root @@src_root end |
#to_s ⇒ String
Create a String representation of this Command
148 149 150 |
# File 'lib/pandocomatic/command/command.rb', line 148 def to_s 'command' end |
#uncount ⇒ Object
Decrement the total number of conversion commands by 1
174 175 176 |
# File 'lib/pandocomatic/command/command.rb', line 174 def uncount @@total -= 1 end |