jacksonecac
jacksonecac

Reputation: 284

delivering executable with gem

I am trying to deliver an exec file with my ruby gem but am not sure how to go about it.

I have a ruby script called pfparser like:

#!/usr/bin/env ruby
ENV['path'] = ARGV[0]
require 'pfparser'

in my pfparser.rb file I want to accept the parameter but it doesn't seem to pass over. The parameter should be a file path that the pfparser.rb file should then parse and return an output. I feel like I am not doing this correctly but I am not sure how to go about it.

This feels like overkill, I want to deliver one file that the user can then execute with a parameter.

Upvotes: 0

Views: 41

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121010

I assume pfparser.rb contains a class definition, that handles all the stuff. So I would go with something like that:

lib/pfparser.rb

class PfParser
  def initialize path
    @path = path
  end

  def do_job
    # change to real stuff
    puts "Hi, path is: #{@path}"
  end
end

bin/pfparser

#!/usr/bin/env ruby
require 'pfparser'
PfParser.new(ARGV[0]).do_job

And now:

$ bin/pfparser PATH
#⇒ Hi, path is: PATH

Upvotes: 1

Related Questions