Skip to content

Instantly share code, notes, and snippets.

@abinoam
abinoam / frontend_api.rb
Created July 9, 2018 16:58 — forked from ErvalhouS/frontend_api.rb
A read-only frontend API abstraction applicable to any application.
# 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
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
class MegaLotto
NUMBERS = 5
def draw
Array.new(NUMBERS){ single_draw }
end
private
def single_draw