Is it possible to place the .irbrc file in the project folder? - ruby

I would like to place the .irbrc file in my project folder to configure the irb console just for that specific project. I am aware that i can configure .irbrc placing it in the home folder but i would like to avoid that, i just want to require all the files of my project when i get into the console, but i am not looking for a permanent behaviour
I am trying to place .irbrc file in the project root but it does not seem to be requiring anything if i place it there.
Is it possible to do it??.
Any suggestion would be much appreciated.
Thank you so much

Does your project have a ./bin/console file? Probably that's what you're looking for.
Here is some information about it: Your Ruby App Should Have a bin/console.
However, you can pass another file to be loaded in irb:
IRBRC="~/Documents/.irbrc" irb
You can look at how irb loads it in init.rb, if you're interested.

Related

hide directory in rails project

I have create a new directory with
FileUtils.mkdir_p 'backupFiles' unless File.exists?('backupFiles')
how ever i like this folder to be hidden from CL and within the text editor visualisation of the rails project.
Any hints or advise how to do so?
and if the folder is hidden would it still be accessible by my program ? (e.g. with FileUtils.cp_r "./app", "backupFiles/")
This will be hard to answer correctly without any clarification on what you mean by "hidden" (I would have asked that in a comment, but reputation you know). I'll try anyway.
What I understand is that your application creates a directory in your app directory that you don't want to see.
If you don't want to see it in the Finder/Nautilus/Windows Explorer, then the easiest way should be to name the directory beginning with period. For your example that would translate to:
FileUtils.mkdir_p '.backupFiles' unless File.exists?('.backupFiles')
This wouldn't affect the accessibility of that folder via the commandline or your app in any way. (Accept that it's name starts with a period obviously)
Maybe that might be possible using SELinux Extended Security Attributes but it sounds pretty hard to implement.
Take a look at this:
https://superuser.com/questions/738392/completely-hide-files-on-linux

Telling rspec to not add directories to $LOAD_PATH

Rspec is automatically adding the lib directory for my project to the load_path. Is there any way to tell it not to do this?
No. As far as I know, no one's ever wanted it to not do this before.
What problems is it causing for you? Most users find it very convenient that rspec adds lib to the load path.
You can always remove the directory from the load path if you don't want it there.

How can I stop Padrino putting compiled SASS in my public/ directory? Or should I?

I'm playing with Padrino, experimenting with a very minimal site at the moment with no DB and just a few HAML and SASS files under the app/ directory.
What I've noticed is that each time I render a page which links to a stylesheet that's defined in a .sass file, it compiles the stylesheet to .css and stores it under public/.
This is all very well, but I also have some static assets stored in public/, including images and some other hand-written .css files.
What this means is that my public/ directory becomes a mix of things I placed there and things compiled by Padrino. So, looking in there will show a bunch of .css files, some of which are compiled .sass files, and some of which are my actual primary static assets. This is confusing.
Is there a way I can stop Padrino (or Sinatra, or Rack, or whatever is doing it) from saving these compiled files during development, and keep my public/ clean?
Alternatively, can someone explain why what I'm asking for is a bad idea / by design / I should learn to love it instead? :-)
Thanks.
I don't know how to set the SASS settings for Padrino, I had a look and couldn't find anything helpful either. I would feel a bit nervous about running it this way too, it could easily get confusing and unhelpful, and what if the asset names clash?
What you could do is not add SASS in via Padrino, and then run it yourself either via the --watch switch or via something like Guard. That way you can also specify different subfolders within the public directory (images/css/js etc), which is what I do (although it does mean you need to remember to add the subfolder as part of the path when describing links). The app doesn't even need to know you're using SASS, and precompilation, when it's this simple, is surely better than the kind of compilation on demand that you've got at the moment (IMO).
You might try the Padrino mailing list for help with the settings.
Using the padrino-sprockets gems I also wanted to change the default /public/stylesheets directory to /assets/stylesheets where sprockets pick them up. I found that my padrino project genereated with the -c sass option had a /lib/sass_plugin.rb file with the following:
# Enables support for SASS template reloading for rack.
# Store SASS files by default within 'app/stylesheets/sass'
# See http://nex-3.com/posts/88-sass-supports-rack for more details.
module SassInitializer
def self.registered(app)
require 'sass/plugin/rack'
Sass::Plugin.options[:template_location] = File.join(Padrino.root, "app/stylesheets")
Sass::Plugin.options[:css_location] = File.join(Padrino.root, "public/stylesheets")
app.use Sass::Plugin::Rack
end
end
Editing the :css_location path and restarting Padrino did the trick!

Accessing an external file from MacRuby

I have done several small scripting/automation projects before but this is my first time using MacRuby and I couldn't find out at all why my project is not working.
This task would have been easy to fix if it was just a plain Ruby script. However, it needs a Mac GUI so I decided to use MacRuby for its Cocoa bindings.
The app itself is a simple form that will perform a calculation based from some data from an external CSV and some text fields and then show the results of the calculation.
My problem is that this code does NOT seem to work:
#arr_from_csv = CSV.read("data.csv")
Upon building the file, I get the following error:
[...]/ruby/1.9.2/CSV.rb:1335:in `open': No such file or directory - open() failed (Errno::ENOENT)
At first, I thought that I must have put the CSV file into the wrong directory inside XCode project's folder structure. I tried putting on the same folder as the script itself (app_delegate.rb). Didn't work. I tried putting it in the Resources folder, still didn't work.
Then, I decided to just use an absolute file path. So, I changed to code into:
#arr_from_csv = CSV.read("~/data.csv")
and copied the file into my home directory. It still can't read the CSV file.
Am I missing something? I'm sorry, this is my first time using MacRuby.
Thanks.
You should change the code to "/Users/xxx/data.csv".
Ruby does not expand "~" to "/Users/xxx".
Notice: xxx represents your login id.
I was able to solve my problem by using:
#arr_from_csv = CSV.read(File.expand_path("~/data.csv"))

Is there a location for custom Ruby libraries to be stored so Ruby can find them?

I have written a module that has some generic, reusable code that I would like to be able to use in other projects. Is there a place I could put this file on computer so that Ruby can find it regardless of where I saved the file that is including it? I am using a Mac.
There's no standard place to put code like this. You could put all your code in a gem and install the gem, or create a directory to put this code in. Once you create the directory, alter the LOAD_PATH global variable to include this directory. You can do this either in each script that uses these, or with the RUBYOPT environment variable. For example, you could put ~/my_ruby_stuff in your path and put your files there. One warning if you do that, make sure the path you add is at the end of the gem path and try to avoid any name conflicts with existing Ruby libraries or gems.
Consider making a "gem" out of your code. The advantages are: separate project, better defined interface, separate source control, can share with other developers in your company, etc

Resources