Ruby & Rails shot

Saturday, May 19, 2012 4 comments

Ruby libs shot

Friday, May 4, 2012 4 comments

method_decorators

Jealous of Java, C#, etc method annotations? Here's a mini gem that gives you the opportunity to do this in Ruby! Watch out :
class ExternalService
  extend MethodDecorators

  +Retry.new(3)
  def request
    ...
  end
end
Source and info : https://github.com/michaelfairley/method_decorators
Spotted through Extending Ruby with Ruby (with explanation and other cool ideas)

anise

Dynamic code annotations
class X
  extend Anise::Annotative::Attributes

  attr :baz, Integer, :max => 10
end

X.ann(:baz)  #=> {:class=>Integer, :max=>10}

Her

An "ORM" for REST apis instead of database models
Her::API.setup :base_uri => "https://api.example.com" do |builder|
  builder.use Faraday::Request::UrlEncoded
  builder.use Her::Middleware::DefaultParseJSON
  builder.use Faraday::Adapter::NetHttp
end
class User
  include Her::Model
end
User.all
# GET https://api.example.com/users and return an array of User objects

User.find(1)
# GET https://api.example.com/users/1 and return a User object

@user = User.create(:fullname => "Tobias Fünke")
# POST "https://api.example.com/users" with the data and return a User object

@user = User.new(:fullname => "Tobias Fünke")
@user.occupation = "actor"
@user.save
# POST https://api.example.com/users with the data and return a User object

@user = User.find(1)
@user.fullname = "Lindsay Fünke"
@user.save
# PUT https://api.example.com/users/1 with the data and return+update the User object