Skip to content

Instantly share code, notes, and snippets.

View brunoandradd's full-sized avatar

Bruno Andrade brunoandradd

View GitHub Profile
module AutorizacaoHelper
extend self
def autorizado_para_modulo?(usuario, modulo)
return true if Rails.env.development?
usuario.acoes.where(modulo: modulo).any?
end
def autorizado_para_secao?(usuario, modulo, secao)
return true if Rails.env.development?
#old code
def filtrar_padrao_por_data(horario, data)
programado_substituto = Agendamento::Horario.programados_por_horario_padrao(horario).where('? BETWEEN validade_inicial AND validade_final', data).first
if programado_substituto # se existe um substituto para ele
if data.between?(programado_substituto.validade_inicial, programado_substituto.validade_final) # e substitui nessa data
if programado_substituto.bloqueado?
false
else
programado_substituto # mostra o substituto
class Unit < ApplicationRecord
store :data, accessors: %i[position phone email], coder: JSON
belongs_to :company, inverse_of: :units, optional: true
belongs_to :unit_parent, class_name: "Unit", foreign_key: "unit_id", optional: true
end
@brunoandradd
brunoandradd / via.rb
Last active September 18, 2019 12:41
#Código atual:
if item.try(:percentual_via)
if item.try(:percentual_via).present?
codigo_via = Convenio::PercentualVia.codigo_da_via(item.percentual_via.tipo)
xml.viaAcesso codigo_via
else
xml.viaAcesso '1'
end
else
@brunoandradd
brunoandradd / odontograma.rb
Created August 20, 2018 22:33
odontograma
class OndontogramaNulo
attr_reader :codigo_dente, :regiao_boca, :face
def initialize
@codigo_dente = 0
@regicao_boca = ''
@face = ''
end
end
x = {:group_name=>"Grupo I",
:subjects=>[
{:subject=>"Previdenciário", :total_answered=>2, :total_correct=>2, :points=>10,
:average=>100.0, :average_course=>100.0,
:leading_knowledges=>[{:name=>"Conhecimento prepoderante 1", :average=>0.0},
{:name=>"Conhecimento prepoderante 2", :average=>0.0},
{:name=>"Conhecimento prepoderante 3", :average=>0.0}]},
{:subject=>"Previdenciário", :total_answered=>2, :total_correct=>2, :points=>10,
:average=>100.0, :average_course=>100.0,
:leading_knowledges=>[{:name=>"Conhecimento prepoderante 1", :average=>0.0},
@brunoandradd
brunoandradd / gist:6f5fe47b92d66df40aae
Created January 14, 2015 13:42
helper_method_example.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
before_action :set_locale
before_filter :authenticate_user!
self.responder = AppResponder
respond_to :html
helper_method :current_salon
@brunoandradd
brunoandradd / Serialize.rb
Created June 19, 2014 20:15
Serialize.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :name, :email
end
class SchedulingSerializer < ActiveModel::Serializer
attributes :id, :beauty_salon_id, :schedule_id, :customer_id,
:date_scheduling, :hour, :beauty_salon
has_many :services
# controller metodo index:
def index
@consultorios = BuscadorConsultorio.new(params).filtrar
end
# novo objeto de busca
class BuscadorConsultorio
def new(opcoes_busca, buscado_padrao = Setor::Consultorio)
class PacientesController < ApplicationController
before_action :protected_show, only: [:show]
def show
@paciente = Paciente.find(params[:id])
end
private
def protected_show
unless clinica_logada.pacientes.where(id: params[:id]).any?