Skip to content

Instantly share code, notes, and snippets.

class Team
attr_accessor :name, :country
private_class_method :new
end
class Barcelona < Team
def initialize(name, country)
@name = name
@country = country
end
@joaquimadraz
joaquimadraz / gist:7213795
Created October 29, 2013 12:32
Remove rails warning
Remove WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Open ~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpresponse.rb
goto line 205 and change it to:
if chunked? || @header['content-length'] || @status == 304 || @status == 204
Change the ruby version in the path to your version
bye bye warning
@joaquimadraz
joaquimadraz / simple_use_cases_folder.rb
Last active January 17, 2019 16:45
Simple use_cases folder example
|- app
| |- use_cases
| | |- users
| | | |- index
| | | | |-- base.rb
| | | | |-- parse_params.rb
| | | |- create
| | | | |-- base.rb
| | | | |-- parse_params.rb
| | | | |-- persist.rb
@joaquimadraz
joaquimadraz / use_case_invoice_example.rb
Created March 18, 2015 18:11
use_case_invoice_example
# USE CASE:
# As a user I want to finalize an Invoice and an email should be delivered to the customer.
class FinalizeInvoiceUseCase < UseCase::Base
depends FindInvoice, ValidateToFinalize, FinalizeInvoice, SendEmail
end
@joaquimadraz
joaquimadraz / simple_use_case_example.rb
Created March 30, 2015 23:41
simple_use_case_example
module App
module UseCases
module Users
module AssignBadge
# REQUIRED CONTEXT:
# - id
# - badge_id
class Base < UseCase::Base
@joaquimadraz
joaquimadraz / ze.rb
Last active August 29, 2015 14:21
merge same key array of hashes
# input = [
# {:alarma=>{:foo2=>"bar2"}},
# {:alarma=>{:foo=>"bar"}},
# {:alarma=>{:test2=>{:foo=>"bar"}}},
# {:cenas=>"teste"},
# {:alarma=>{:foo2=>"bar2", :foo=>"bar"}}
# ]
input = [
{:foo=>{:foo=>{:bar=>"stuff"}}},
@joaquimadraz
joaquimadraz / internal_task.rb
Created May 30, 2015 10:24
internal_task.rb
require 'internal_task/version'
module InternalTask
extend Rake::DSL
namespace :internal_task do
desc 'Say hello'
task :hello do
@joaquimadraz
joaquimadraz / api_level_validations_with_grape.rb
Last active August 29, 2015 14:28
API level validations with Grape
require 'grape'
module Blog
class Web < Grape::API
...
desc "Create post comment"
params do
requires :id, type: Integer
@joaquimadraz
joaquimadraz / user_model_example.rb
Last active August 29, 2015 14:28
User model example
class User < ActiveRecord::Model
default_scope { where(state: 'active') }
scope :inactive, -> { where(active: false) }
validates_presence_of :first_name, :last_name, :email, :password, :invitation_token
validates :first_name, length: { minimum: 2 }
validates :last_name, length: { minimum: 2 }
@joaquimadraz
joaquimadraz / user_create_use_case.rb
Last active August 29, 2015 14:28
User create use case, validate, complete_date and save
module UseCases
module User
module Create
class Validate < RestMyCase::Base
# all necessary validations to persit
context_reader :user,
:user_attributes