Class: Byggvir::Multiple
Class Method Summary collapse
-
.commands(inst) ⇒ Object
List existing commands.
- .create_binaries ⇒ Object
- .doc(doc, name = nil) ⇒ Object
-
.new(*args) ⇒ Object
Instantiate a multiple function object.
Class Method Details
.commands(inst) ⇒ Object
List existing commands
19 20 21 22 23 24 25 26 27 |
# File 'lib/byggvir.rb', line 19 def commands(inst) unless @docs @docs = (inst.methods.to_set - TestObject.new.methods.to_set).map{|meth| [meth,"Options: "+::Byggvir.parameters(inst.instance_eval{self.class.instance_method(meth)}).keys.join(?,)] }.to_h end longest = @docs.keys.map(&:length).max @docs.map{ |k,v| Kernel.sprintf("% #{longest+1}s : %s",k,v)}.join("\n") end |
.create_binaries ⇒ Object
7 8 9 10 |
# File 'lib/byggvir.rb', line 7 def create_binaries() directory = File.mkdir(File.basedir($0)+"/bin") list_existing_methods.each{""} end |
.doc(doc, name = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/byggvir.rb', line 12 def doc(doc,name=nil) ::Byggvir.error!("doc has to end with a comma, #{caller[1..1]}") unless name.class == Symbol @docs||={} @docs[name]=doc end |
.new(*args) ⇒ Object
Instantiate a multiple function object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/byggvir.rb', line 30 def new(*args) inst=super(*args) ::Byggvir.error!("Please specify a method, One of: \n#{commands(inst)}") unless ARGV.length>0 name = ARGV[0].to_sym ARGV.drop(1) begin meth = instance_method(name) rescue NameError => ex ::Byggvir.error!("No method #{name.to_s} defined in #{$0}, try one of \n#{commands(inst)} (#{ex})") else ::Byggvir.wrap(inst,meth) end end |