Forum: Ruby on Rails [BUMP] conditional require? conditional action code?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jodi S. (Guest)
on 2006-05-06 04:14
(Received via mailing list)
Greetings all.

I have some controller code that uses win32ole (only available on
windows). This code is now solid, and I'd now like to resume
development on (any) other OS(grin).

But alas, the controller bails because the OS specific library can't
be found.

Can I conditionally specify action code compilation (and a require
'win32ole') based on OS or maybe an environment variable?
(I'm thinking C #IFDEFs)

Or perhaps an empty stub win32ole library for OSX/Linux?

Thanks for your thoughts.

Cheers,
Jodi
Eden B. (Guest)
on 2006-05-06 04:38
(Received via mailing list)
I think you will want to hide the OS dependent stuff in a class.  The
class
can then detect the operating system and respond with the desired
functionality if available, or fail gracefully if not.  I think you can
detect the operating system from the Ruby config file.  This is from
"Programming Ruby":

require "rbconfig.rb"
include Config
CONFIG["host"] â?? "i686-pc-linux"
CONFIG["LDFLAGS"] â?? "-rdynamic"

Try playing around with CONFIG and see if there are values in there that
will tell you what you need to know.

Eden
Jodi S. (Guest)
on 2006-05-06 04:53
(Received via mailing list)
Great info Eden - thanx. I'll dig in.
Jodi S. (Guest)
on 2006-05-06 05:36
(Received via mailing list)
Although my implementation will vary the core code looks like,

   require 'rbconfig'
   include Config

   require 'win32ole' if CONFIG["build_os"] =~ /mswin/

Thanx Eden - Happy to be back testing on osx!

J
This topic is locked and can not be replied to.