Is there a generic way to receive the path to a Magento module? I want to link to an configuration file in the /etc folder in one of my modules.
You can ask for paths with getModuleDir method
Mage::getModuleDir('Model', 'Your_Extension');
Mage::getModuleDir('Block', 'Your_Extension');
Mage::getModuleDir('Helper', 'Your_Extension');
Mage::getModuleDir('controllers', 'Your_Extension');
Mage::getModuleDir('etc', 'Your_Extension');
getModuleDir only works where the first parameter is 'etc', 'controllers', 'sql', or 'locale'. Of course, you could just pass in a '' as the first parameter and append 'Model'/'Block'/'Helper' to the returned value.
Related
How can I store a file with the absolute path /var/www/cityscape/public/storage/img/newyork.jpg?
I tried Storage::put() (https://laravel.com/docs/5.3/filesystem#storing-files), but this method seems to only accept relative paths.
If the path you've specified in your question is in the same system as your app you can use File instead:
File::put('/var/www/cityscape/public/storage/img/newyork.jpg', $theFile);
Hope this helps!
How can I open a form stored in the current directory
do form ADDBS( JUSTPATH(SYS(16,0))) +"\form5.scx" WITH thisform.grid1.Column1.Text1.Value TO aa
I tried this but says that the file doesn't exist
do form form5 with ...
VFP uses relative pathing and also search paths. If it is in current directory then would be the first one to be picked by VFP.
ADDBS( JUSTPATH(SYS(16,0)))
this adds already a slash ("\") to the path and you add another slash with "\form5.scx"
can do
do form ADDBS( JUSTPATH(SYS(16,0)))+"form5.scx"
or use relative path or locfile() function
to test what i said copy this code and execute it: you can see there is 2 "\"
addbs() works only on what its applied not in the second independent term of the path.
local m.myvar
text to m.myvar noshow
messagebox(ADDBS( JUSTPATH(SYS(16,0))) +"\form5.scx")
_cliptext=ADDBS( JUSTPATH(SYS(16,0))) +"\form5.scx"
endtext
strtofile(m.myvar,"test.prg")
do test
Can someone explain me exactly (better if with examples) the meaning of the dereference_root option in FileUtils.cp_r and in other class method of the same class?
Thank you in advance.
It applies only if your source file/directory is symbolic link. If it is and you specify this option, then FileUtils.cp_r will follow this link and copy the original files otherwise you will get just a copy of the symlink.
But this doesn't apply recursively. So if you will have other symlinks inside your source folder they will be just copied as is, without 'dereferencing'.
So currently I have included the following in my .bashrc file.
export RUBYLIB=/home/git/project/app/helpers
I am trying to run rspec with a spec that has
require 'output_helper'
This file is in the helpers directory. My question is that when I change the export line to:
export RUBYLIB=/home/git/project/
It no longer finds the helper file. I thought that ruby should search the entire path I supply, and not just the outermost directory supplied? Is this the correct way to think about it? And if not, how can I make it so RUBY will search through all subdirectories and their subdirectories, etc?
Thanks,
Robin
Similar to PATH, you need to explicitly name the directory under which to look for libraries. However, this will not include any child directories within, so you will need to list any child sub-directories as well, delimiting them with a colon.
For example:
export RUBYLIB=/home/git/project:/home/git/project/app/helpers
As buruzaemon mentions, Ruby does not search subdirectories, so you need to include all the directories you want in your search path. However, what you probably want to do is:
require 'app/helpers/output_helper'
This way you aren't depending on the RUBYLIB environment variable being set a certain way. When you're deploying code to production, or collaborating with others, these little dependencies can make for annoying debugging sessions.
Also as a side note, you can specify . as a search path, rather than using machine-specific absolute paths.
How would I, say, determine if the file ~/.my_proj_config exists on any OS in Ruby?
A call to Dir.home is a OS independent way to get to the home directory for the user. You can then use it like
File.exists?(File.join(Dir.home, ".my_proj_config"))
This works in Ruby 1.9, but note that the call to expand_path is required on some systems (e.g. Windows):
File.exists?( File.expand_path "~/.my_proj_config" )
Use the class File and its method exist?.
Take a look at the Pathname class, specifically the realpath function - This will get you the full (expanded) path to your file.
http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pathname.html#M001991
You then use the File class along with exists? method to find out if that exists. You shouldn't need to use realpath if you use this method, however.
http://www.ruby-doc.org/core/classes/File.html#M000045