This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example from: http://hanamirb.org/guides/1.2/getting-started/#implementing-create-action | |
module Web::Controllers::Books | |
class Create | |
include Web::Action | |
def call(params) | |
BookRepository.new.create(params[:book]) | |
redirect_to '/books' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Api | |
module V1 | |
# Controller to consume read-only data to be used on client's frontend | |
class FrontEndController < ActionController::API | |
include Orderable | |
# GET /:resource | |
# GET /:resource.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FactoryGirl::Syntax::Methods | |
def find_or_create(name, attributes = {}, &block) | |
factory = FactoryGirl.factory_by_name(name) | |
clazz = factory.build_class | |
factory_attributes = FactoryGirl.attributes_for(name) | |
attributes = factory_attributes.merge(attributes) | |
clazz.find_or_create_by(attributes, &block) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This codeship custom script depends on: | |
# - API_KEY env var from Heroku | |
# - STAGING_APP_NAME | |
# - STAGING_APP_URL | |
set -e | |
export HEROKU_API_KEY="${API_KEY}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MegaLotto | |
NUMBERS = 5 | |
def draw | |
Array.new(NUMBERS){ single_draw } | |
end | |
private | |
def single_draw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def the_main_script | |
# Your main script | |
# Do whatever here | |
x = rand(3) | |
puts "x = #{x}" | |
puts "and 10/#{x} = #{10/x}" # When x==0 ZeroDivisionError | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'psych' | |
class ScalarHandler < Psych::Handler | |
def parser=(parser) | |
@parser=parser | |
end | |
def mark | |
@parser.mark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def append_data_to_daily_files | |
Dir.entries('A').each do |file| | |
next unless file.match(/today/i) | |
File.open(File.join("A",file), 'a') do |file| | |
file.puts("hello") | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
regexp = /^([A-Z]{1,4})([0-9]{1,4})$/ | |
text_phrases = | |
[ "ABCD1234", | |
"ABCDE1234", | |
"ABCD12345", | |
"ABCDE12345"] |
NewerOlder