Ruby/Gem/Bundler Caching my local gem files - ruby

I'm working on a gem locally, referenced it using bundle config local.GEMNAME (this is confirmed by the printout of bundle install). However, unless I bump the version on the gem, I can't use the most up-to-date code. When errors occur in the old code, it references the file in the right place, where I have fixed the error. I temporarily had bundler-cache-all switched on, but have turned that to false (and deleted .bundle/config).
Where is this cache living (I'm on OSX, using RBenv and ruby 2.1.2), and how can I turn it off?

Have you tried running spring stop and restarting your server (assuming this is a Rails app)?
If it's referencing the file in the right place but executing the wrong code, that indicates that the old code is still loaded into memory. Often, this is because of the Spring pre-loader, which is used by default with Rails 4.1+.

Related

Chef Test Kitchen fails to load ffi-yajl c-extention

Yesterday my system configuration was such that I could smoothly run kitchen test without issue. I don't know what happened, but this morning the configuration was all screwy and Kitchen wouldn't run. Something about Berkshelf having no cdhash or something. I spent literally all day hammering it out, and I've finally got kitchen test running to completion, but partway through (after Vagrant brings up the VM and it connects over SSH and starts to converge) it tells me:
...
Vagrant instance <default-centos-6> created.
Finished creating <default-centos-6> (2m20.75s).
-----> Converging <default-centos-6>...
Preparing files for transfer
Preparing dna.json
Resolving cookbook dependencies with Berkshelf 8.0.5...
failed to load the ffi-yajl c-extension, falling back to ffi interface
...
That last line about the ffi-yajl c-extension is the problem. Like I said, it still runs the tests to completion, but it pauses here and ffi takes a while to run, while ffi-yajl used to be pretty fast. Also, it worked yesterday before whatever hex took over my computer. For the purpose of expedience in running tests against multiple configurations, it'd be great if the faster ffi-yajl stuff could work but I don't know what to do. I found an ancient git issue on the ffi repo from 2015 (and on windows, I'm on Mac 12.5.1, if it matters) but I assume whatever upcoming patch mentioned in the response has since been released since 2015.
gem list ffi-yajl says I have 2.4.0. If it matters, the ffi version it's falling back to is 1.15.5.
When I do which -a ruby, it shows me the system ruby (/usr/bin/ruby) and the chef-workstation ruby (/opt/chef-workstation/embedded/bin/ruby). I think one of the steps I did earlier to fix my configuration was to tell it to use the chef-workstation ruby, but I don't remember how I did that (maybe the PATH variable?). Could it be that ffi-yajl's gem is in the wrong place associated with the system ruby? How would I correct that if that's the case? How would I determine if that's the problem?
I tried gem install ffi-yajl, but no luck. I tried bundler pristine ffi-yajl; bundle install, but also not helpful. Before you ask, I've been tasked with working on this portion of our tech stack, partially because we have a lot of tech debt like this, and partially because it's an opportunity for me to learn something new about our tooling. In other words: I'm completely inexperienced with all things Ruby/Gems/Bundler, so I've been throwing ideas on the wall and hoping something sticks, but I'm still searching. I'm out of ideas.

Rubymine use local gem configuration

I'm running Ruby mine 7.1.2 on Windows and I'm having difficulty with it because it seems to want to use its own gems and version of fun where. My application works fine from the command line if I do bundle install or bundle exec rails script but when I try to run from the IDE it complains about missing gems.
I could just try to reinstall all the gems via ruby mine but some of the gems require special customization in Windows and doing that from the command line is much easier. Is there anyway I can have ruby mine just use the gems which are already installed?
Rubymine will usually bundle your ruby SDK (i.e. ruby itself) and all it's associated gems so that you don't end up with weird configuration dependencies.
If you want to circumvent that then follow an official guide. In addition to that guide, be aware that there are also per-run SDK settings. These kick in when running or debugging a RubyMine project and need to be configured in the run -> configuration settings dialog.
My (unsolicited) additional advice is that I'd recommend figuring out what aspects of your global ruby installation are causing issues with RubyMine's bundle installer. The reason RubyMine sandboxes several SDKs is to reduce major headaches when you go to deploy your applications. Without it, you might encounter dependency hell when you deploy your application. From my personal (and extremely annoying) experience, rushing these initial set-up steps tend to come back with vengeance when you want to run ruby apps elsewhere.

Issues after upgrading Ruby & Rails

I upgraded my Ruby to 2.1.2 & I upgraded Rails to 4.1.2.
I currently have 2 issues that I can't seem to get passed and they may be interconnected.
First, I get this error: Could not find attr_encrypted-1.3.2 in any of the sources when CLEARLY when I run bundle install it says Using attr_encrypted (1.3.2).
Second, before this, I noticed that when I do rails c the version of Ruby is 2.0.0, but ruby --version outputs ruby 2.1.2p95 and rvm lists shows that I am using Ruby 2.1.2. Frustrating, and I think these issues may be interconnected.
bundle install does not fix it. Deleting my Gemfile.lock does not fix it.
Bet its spring again, caching your app.
spring stop
Edit 1
Spring is a rails application preloader. It caches the app, making running rails commands, task, tests etc. faster by saving rails load time. It's default since rails 4.1. Check your bin folder. There will be binstubs within. Open bin/rails and you'll see it loading spring which does the caching magic.
In 99% of the time rails will pick up your code changes. But this won't be the case on changing startup code like gem loading.

Rails 3.1 not detecting Coffeescript and Javascript changes?

Sometimes I update my Coffee code in Rails 3.1 and it doesn't detect any of the changes, ie. I refresh my browser/cache and it still invokes the old script. Anyone know what causes this?
EDIT: I even litter my entire scripts with "debugger" and none of them ever gets called. Any idea why it simply won't refresh the Coffeescripts?
EDIT2: I realize that it doesn't even detect javascript changes sometimes. Am I missing something? Note I am not bouncing my server when I change JS files... It used to work...
For the development environment you could try to rake assets:clean. Rails sometimes reads the precompiled assets in development environment, so this will clean them and the fresh ones will be loaded.
For the production environment try to rake assets:precompile, so that the changes are compiled and stored in the assets files.
For the curious, it suddenly started functioning correctly again by itself. I have reason to believe it was actually the Daylight Savings Time that caused this bug. Not sure if this could be the case but it suspiciously started working again naturally after a fixed amount of time (about 1 hour).
Try rake assets:precompile, if you haven't already.

Ruby problem(bug)- in rake gem

i am running ruby 1.9.2p0 on rails on windows OS with rubymine 3.1.1.
i use it for גseveral weeks.
a few days ago- i tried to run my project from rubymine and the console notification was:
"Could not find rake-0.8.7 in any of the sources
Process finished with exit code 7"
i googled it and i found reference to this problem in several places. the solution repeated most often was to delete the non-versioned "rake.gemspec" file.
i tried this solution but the problem is not resolved, it still says the same notification.
i trying to solve this problem for several days!!!
please help me if you know how!!!
thanks a lot in advanced!
Asaf,
I've had literally hours of frustration dealing with similar problems. The solution can be a challenge to track down, because there are numerous reasons you could be having the problem. I'm no expert myself, but I'll try to pass on some of what I've learned.
First, you mentioned getting an error about Rake, but didn't mention that you had tried to actually run Rake. Are you getting the error upon loading up RubyMine or specifically after running a Rake command?
Next, if you are running a Rake command and getting an error, you should take note that WHERE you run the command from is pretty important. For example, if you keep a Terminal window open like I do, and run the Rake command from Terminal, you won't necessarily get the same results you would get by running Rake from RubyMine itself. The reason for this was not self-evident when I first started with RubyMine, but I think it comes down to this:
The Ruby SDK and Gems preferences in RubyMine should be determining what types of dependency errors you get from within RubyMine. So you might start by looking there to see if there are any dependency errors. Next, I would guess that you're running RVM? Please be aware that it is completely possible to be using one RVM set in RubyMine (check the Ruby Interpreter in SDK and Gems Preferences to see which one you're using) and an entirely different RVM in Terminal (the command "RVM info" should get you the version you're using). If those don't match, you could very well get different results from both RubyMine and Terminal, even when running exactly the same commands.
My solution to this problem was to carefully ensure that both of my environments matched. I think you can set RVM defaults by typing "rvm default" plus the version you want to default to. That way both your Terminal and RubyMine environments match.
Lastly, be aware that RubyMine allows more than one version of a Gem to be installed at the same time. So, if you're getting an error that a Gem is failing because some dependency requires a specific version, you can tell RubyMine to install multiple versions. Do this thru the SDK manager, select the Gem, then click "Select Versions".
Hopefully some of this information applies to your issue. I sort of did the shotgun approach, because I'm not really sure what is causing your error, but maybe some of this can put you on the right path. One final note would be this: Use your Gemfile to control Gem versions, if need be. I've spent hours of frustration over broken dependencies, only to discover that the reason for the break was me telling RubyMine to update all my Gems to the latest version. The latest version of a particular Gem isn't necessarily backwards compatible with previous versions, and blindly updating Gems can cause huge problems.
Asaf, you should delete rake.gemspec and run gem install rake to get problem fixed

Resources