I published a gem earlier this week which allows developers to add gems to their Gemfile from the command line. The utility of Gemrat lies in it’s ability to grab the latest version of a gem and lock it into your Gemfile.
Example
$ gemrat sinatra
#=> gem 'sinatra', '1.4.3' added to your Gemfile.
#=> Bundling...
$ gemrat rspec
#=> gem 'rspec', '2.13.0' added to your Gemfile.
#=> Bundling...
Lately I’ve been taking a service oriented approach to developing software. This means that I build smaller apps which depend on each other rather than having a huge monolithic codebase.
This approach lends itself to reusability, polyglot programming, and it gives me more chances to implement lessons learned from previous applications.
The service oriented approach also carries some debt. I’m often wrangling dependencies as I rebuild infrastructures. Developers working on monolithic apps with lots of legacy code can go days or weeks without adding dependencies. This is usually not the case in service oriented architectures.
The manual process of adding gems usually involves searching for the latest version of a gem then adding the gem and it’s version to the Gemfile. This process calls for a browser and text editor.
The same result can now be accomplished by running $ gemrat gem_name from your command line.
I use this tool on a daily basis. Solving my own problems and sharing solutions with the world is extremely gratifying work.
“Please point sidekiq to a Rails 3 application or a Ruby file to load your worker classes with -r DIR|FILE.”
I received this error while attempting to use Sidekiq in a Sinatra app. To solve this problem, use the -r option to point Sidekiq to your main Sinatra file.
123
...`sidekiq: bundle exec sidekiq -r ./app.rb`...
The -r option is also used by pry to preload dependencies.
pry -r ./app.rb gives you access to all our your methods in app.rb without the need to require it via console.
I had this issue earlier, here is how I solved it.
Jasmine spec runner was returning ‘Error: Unexpected request: GET /locations/1 No more request expected.’ I stubbed the call by specifying the action (GET) and the path (‘locations/1’). If you are relying on the response data in your test then return the appropriate JSON object(s) instead of an empty array.
I’m building an AngularJS app with Rails 4 as an API and router. Using Rails for routing causes problems as users follow links, controller code on different pages isn’t being loaded. To solve this problem, I force page reloading by adding target=_self to links.
Yesterday I ported some existing code to a different gem. Instead of returning objects, the new gem returns hashes. To stave off a major refactor, I casted each hash to an OpenStruct which allows you get hash values with dot notation.
house = {}
house["bedrooms"] = 5
house = OpenStruct.new house
house.bedrooms #=> 5
I wanted to add a foreign key to an existing table using Rails’ references feature but this was not an option for existing tables. The good news is that Rails 4 makes it possible.
I prefer references because it allows you to be lazy by automatically adding the foreign key and index.
$ rails g migration AddUserRefToProducts user:references
This migration will add a user_id column to your products table and index it.
I installed my project’s dependencies locally while debugging. It didn’t take long to notice that control-P would pick these files up while fuzzy searching. This rendered control-P useless as it presented me with gems that I didn’t care about editing.
My solution was to instruct control-P to ignore files in the vendor directory by adding this line to the .vimrc file:
I came across iconmonstr yesterday while searching for icons to use in my new app. I decided to go with a set instead but they definitely had some cool stuff.
This is a super useful method. Most developers tend to use SCSS just like CSS but there are tons of possibilities in this extension of CSS.
Yesterday I decided to invest some time in refactoring my stylesheets to take advantage of this power. A common pattern that I developed involved the @extend method.
Use Case
Imagine that you need to display profits and losses. You have two classes for each group which are very similar except for the text color.
@extend allows you to abstract common attributes and focus on what’s unique about each class.
This helps a lot when prototyping UIs. I no longer need to jump around my stylesheet to update properties. I can simply modify the extended class in most cases.
#= require_tree ../../app/assets/javascripts#= require angular-resource#= require angular-mocksdescribe"whatAmI Filter",->beforeEachangular.mock.module("ExampleApp")it"returns I'm true if the expression is true",inject((whatAmIFilter) ->expect(whatAmIFilter(true)).toBe"<span class="answer-true">I'm true</span>")it"returns I'm false if the expression is false",inject((whatAmIFilter) ->expect(whatAmIFilter(false)).toBe"<span class="answer-false">I'm false</span>")
Notes
I’m using JasmineRice to test Angular in my Rails app.
Notice that the mock name ExampleApp corresponds to the name of the app. This is not optional. You cannot mock something that doesn’t exist.
Filter should be appended to the name of your filter when evaluating it directly in the test.
I wrote my first AngularJS filter today. I needed to render HTML although I used Haml for templating and it was my first time implementing the ng-bind-html directive.
Here’s a pattern that illustrates what I achieved. I’m using a simple example to illustrate the powerful concept of filtering.
I ran into this issue after coming into a project where the client-code was developed first. An unused test model was created by the previous pair. As I began writing tests for the app, this test model caused a namespace conflict.