Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

Aleksey Leshchuk alekseyl

💭
I may be slow to respond.
View GitHub Profile
@alekseyl
alekseyl / mini-apivore-example.rb
Last active Nov 9, 2017
mini-apivore example
View mini-apivore-example.rb
#cards_api_test.rb
require 'test_helper'
require 'mini_apivore_helper'
class CardsApiTest < MiniApivoreTest
test 'cards unauthorized' do
card = cards(:valid_card_1)
# check route asserts response code and response structure.
check_route( :get, '/cards.json', NOT_AUTHORIZED )
@alekseyl
alekseyl / swagger-docs-exmaple-quote.rb
Created Nov 8, 2017
swagger doc example for my note from sitepoint.com/do-the-right-thing-and-document-your-rails-api-with-swagger/
View swagger-docs-exmaple-quote.rb
class Api::V1::UsersController < ApplicationController
.....
# POST /users
swagger_api :create do
summary "To create user"
notes "Implementation notes, such as required params, example queries for apis are written here."
param :form, "user[name]", :string, :required, "Name of user"
param :form, "user[age]", :integer, :optional, "Age of user"
param_list :form, "user[status]", :string, :required, "Status of user, can be active or inactive"
response :success
View apipie_example_quote.rb
class UsersController < ApplicationController
resource_description do
formats [:json]
api_versions 'public'
end
api :POST, '/users' 'Create user'
description 'Create user with specifed user params'
param :user, Hash, desc: 'User information' do
@alekseyl
alekseyl / minitest-apidoc-quote.rb
Created Nov 8, 2017
minitest apidoc quote for API-comparision tech note
View minitest-apidoc-quote.rb
require_relative "../../spec_helper"
document Albums::Create do
meta :group, "Albums"
meta :request_method, "POST"
meta :request_path, "/albums"
meta :description, "Creates a new album with the given parameters."
param "name", "Name of the album", required: true
@alekseyl
alekseyl / rswag_quote.rb
Created Nov 8, 2017
rswag quote for API documenting note
View rswag_quote.rb
# spec/integration/blogs_spec.rb
require 'swagger_helper'
describe 'Blogs API' do
path '/blogs' do
post 'Creates a blog' do
tags 'Blogs'
consumes 'application/json', 'application/xml'
@alekseyl
alekseyl / switch.rb
Last active Jun 13, 2017
Chef switch recipe for green/blue deploy
View switch.rb
# in order to access ENV you need to include your env recipe
include_recipe 'application::env'
chef_gem 'aws-sdk' do
version '2.7.9'
end
require 'aws-sdk'
owc = Aws::OpsWorks::Client.new( region: 'us-east-1' )
@alekseyl
alekseyl / model.rb
Last active Mar 31, 2021
Active record model template upgraded.
View model.rb
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
# Rails style guided+
#-------------------- 1. includes and extend --------------
#-------------------- 2. default scope --------------------
#-------------------- 3. inner classes --------------------
#-------------------- 5. attr related macros --------------
#-------------------- 6. enums ----------------------------
#-------------------- 7. scopes ---------------------------
@alekseyl
alekseyl / ar_example.rb
Last active Mar 31, 2021
Active record structure
View ar_example.rb
# Rails style guided+
#-------------------- 1. includes and extend --------------
#-------------------- 2. default scope --------------------
#-------------------- 3. inner classes --------------------
#-------------------- 4. constants ------------------------
#-------------------- 5. attr related macros --------------
#-------------------- 6. enums ----------------------------
#-------------------- 7. scopes ---------------------------
#-------------------- 8. has and belongs ------------------
#-------------------- 9. accept nested macros ------------
@alekseyl
alekseyl / conditional_location.conf
Last active Feb 21, 2017
Conditional location selection with try_files. It may be useful in cases of A\B version of a site running on same domain name. You can do sticky cookie with this example.
View conditional_location.conf
server {
set $versioned_location @version_one;
if ( $cookie_condition ) {
set $versioned_location @version_two;
}
if ( $cookie_site_version = "version_one" ) {
set $versioned_location @version_one;
}
@alekseyl
alekseyl / devise_notification_threaded_example.rb
Last active Feb 17, 2017
deliver devise emails with threads
View devise_notification_threaded_example.rb
def send_devise_notification(notification, *args)
# don't forget email not sended without calling deliver
message = devise_mailer.send(notification, self, *args)
# this is the params you want to anylise when something crashes
add_to_airbrake_notice = attributes.slice('email', 'name', 'surname', 'cell', 'id')
# run message delivering
run_async_with_rescue(add_to_airbrake_notice) { message.deliver }
end