Class: MiniMagick::Tool::OptionMethods

Inherits:
Module
  • Object
show all
Defined in:
lib/mini_magick/tool.rb

Overview

Dynamically generates modules with dynamically generated option methods for each command-line tool. It uses the ‘-help` page of a command-line tool and generates methods from it. It then includes the generated module into the tool class.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_name) ⇒ OptionMethods

Returns a new instance of OptionMethods.



203
204
205
206
207
# File 'lib/mini_magick/tool.rb', line 203

def initialize(tool_name)
  @tool_name = tool_name
  reload_methods
  self.class.instances << self
end

Class Method Details

.instancesObject

think about it for a minute



199
200
201
# File 'lib/mini_magick/tool.rb', line 199

def self.instances
  @instances ||= []
end

Instance Method Details

#reload_methodsObject

Dynamically generates operator methods from the “-help” page.



216
217
218
219
220
# File 'lib/mini_magick/tool.rb', line 216

def reload_methods
  instance_methods(false).each { |method| undef_method(method) }
  creation_operator *creation_operators
  option *cli_options
end

#to_sObject



209
210
211
# File 'lib/mini_magick/tool.rb', line 209

def to_s
  "OptionMethods(#{@tool_name})"
end