Skip to content

Instantly share code, notes, and snippets.

View jordifierro's full-sized avatar

Jordi Fierro jordifierro

View GitHub Profile
#!/bin/sh
exec 5>&1
androidTestResult=$(adb shell "am instrument -w \
com.jordifierro.androidbase.presentation.test/\
com.jordifierro.androidbase.presentation.TestMockerRunner ; printf \"$?\"" \
| tee /dev/fd/5)
exitCode=$(printf "%s" "$androidTestResult" | tail -1)
if [ "$exitCode" != "0" ]; then
language: android
env:
global:
- ADB_INSTALL_TIMEOUT=8
android:
components:
- tools
- platform-tools
require 'date'
module Api::V1::Concerns
module VersionExpirationHandler
extend ActiveSupport::Concern
included do
before_action :check_expiration!
end
module Api::V1::Concerns
module Internationalizator
extend ActiveSupport::Concern
included do
before_action :set_locale
end
def set_locale
I18n.locale = extract_locale_from_accept_language_header ||
module Api::V1::Concerns
module ErrorHandler
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::RecordNotFound, with: :not_found
end
def render_error(message, status)
status_code = Rack::Utils::SYMBOL_TO_STATUS_CODE[status]
@jordifierro
jordifierro / authenticator.rb
Last active February 22, 2016 15:51
Example of a Rails api authentication module using ActiveSupport::Concern
module Api::V1::Concerns
module Authenticator
extend ActiveSupport::Concern
included do
before_action :auth_with_token!
end
def current_user
@current_user ||= User.find_by(auth_token: request.headers['Authorization'])
@jordifierro
jordifierro / authenticator_spec.rb
Last active February 22, 2016 15:52
Example of an Rspec definition to test an ActiveSupport::Concern
require 'spec_helper'
module Api::V1
describe Concerns::Authenticator, type: :controller do
controller(ApiController) do
def fake_current_user
render json: current_user
end
end
@jordifierro
jordifierro / api_controller.rb
Last active February 4, 2018 14:17
Example of an Rails api ApiController when using ActiveSupport::Concern to encapsulate controllers common code
module Api::V1
class ApiController < ApplicationController
include Concerns::Authenticator
include Concerns::ErrorHandler
include Concerns::VersionExpirationHandler
include Concerns::Internationalizator
end
end