Jump to content
Sign in to follow this  
steviebraga

ruby require_relative

Recommended Posts

Hi guys,
 
I'm trying to create one workflow using a script filter with ruby. When i put everything in alfred script box it works fine, but i'd like to keep thing organized, so I tried to create 3 separate files, that are placed in workflow folder, and then use alfred script box just to call the methods defined in this files. Something like this:
 
require_relative "file1"
require_relative "file2"
require_relative "file3"


...


puts some_method(param)
 
But when I do this, I get this exception:
 
[ERROR: alfred.workflow.input.scriptfilter] Code 1: -e:1:in `require_relative': cannot infer basepath (LoadError)
from -e:1:in `<main>'

So, is it possible to do something like this. If yes, how?

 

Thanks!

Edited by steviebraga

Share this post


Link to post

 

Hi guys,
 
I'm trying to create one workflow using a script filter with ruby. When i put everything in alfred script box it works fine, but i'd like to keep thing organized, so I tried to create 3 separate files, that are placed in workflow folder, and then use alfred script box just to call the methods defined in this files. Something like this:
 
require_relative "file1"
require_relative "file2"
require_relative "file3"


...


puts some_method(param)
 
But when I do this, I get this exception:
 
[ERROR: alfred.workflow.input.scriptfilter] Code 1: -e:1:in `require_relative': cannot infer basepath (LoadError)
from -e:1:in `<main>'

So, is it possible to do something like this. If yes, how?

 

Thanks!

 

 

Within the script box, a require would typically work normally for files located within the workflow directory. I'm not sure with the require_relative. Have you tried a regular "require"? I would think require_relative would work as well but can't say for sure

Share this post


Link to post

When I tried the regular require, I got this error:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- cpf (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

But googling overnight, I found a solution: instead of using require, I used load and everything is working now!

load "cpf.rb"

Thanks for your time!

Edited by steviebraga

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  
×
×
  • Create New...