This is something quite simple that I just don't know how to implement in the best way.
Let me explain better - I'm working on a project called risg: it's a program that parses IRC logfiles and generates fancy statistics based on them.
Now, it's obvious that it needs to support many kinds of logfile formats and output formats: you can see that I've implemented a system for both logfile formats and output formats (see lib/risg/format and lib/risg/output).
But there's one problem - I don't know how to allow the user to decide which format to use for logfiles and output. If I add a command line switch like "--format" to the main executable, how should I load and instiate the right class from the format directory based on user input?
And while I'm at it, I've been wondering if I should package the application as a Rubygem: is it an optimal way of deployment/distribution?
Loading class from folder based on user input
Page 1 of 13 Replies - 1066 Views - Last Post: 08 October 2009 - 11:04 AM
Replies To: Loading class from folder based on user input
#2
Re: Loading class from folder based on user input
Posted 08 October 2009 - 09:44 AM
Gems are nice.
As for selecting the correct format:
You could have a variable that will hold the log somehow.
Have some sort of conditional
As long as each format conforms to the same interface, i.e. it has some sort of method that you can call throughout the program (something like write, log, etc), you should be good to go.
As for selecting the correct format:
You could have a variable that will hold the log somehow.
Have some sort of conditional
if format1 require "format1" logger = format1.new(args) else require "format2" logger = format2.new(args) end #endif
As long as each format conforms to the same interface, i.e. it has some sort of method that you can call throughout the program (something like write, log, etc), you should be good to go.
#3
Re: Loading class from folder based on user input
Posted 08 October 2009 - 10:18 AM
I did obviously think of doing that, but it occurred to me that somebody might want to write their own log/output format, and that they could simply put it into the right directory and it would be usable without any other source hacks.
#4
Re: Loading class from folder based on user input
Posted 08 October 2009 - 11:04 AM
I mean I don't see any issue with using the command line argument, and then a
require "#{ARGV[0])" and maybe having a default value if they don't specify one.
require "#{ARGV[0])" and maybe having a default value if they don't specify one.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|