Skip to content

Instantly share code, notes, and snippets.

View nfilzi's full-sized avatar

Nicolas Filzi nfilzi

View GitHub Profile
CyLemeunier
@nfilzi
nfilzi / private_attr_methods_decorators.rb
Last active March 4, 2018 14:34
Module to get decorators for POROs to make `attr_*` private
module PrivateAttrMethodsDecorators
module Explicit
module ClassMethods
def private_attr_reader(*attributes)
attributes.each do |attr|
attr_reader attr
private attr
end
end
class Rapper < ApplicationRecord
belongs_to :agent, class_name: "User"
has_many :bookings
end
class User < ApplicationRecord
has_many :rappers, foreign_key: :agent_id
has_many :bookings
# source: -> pour spécifier à AR qu'il doit aller chercher la relation bookings du rapper comme source pour les reservations
class CreateUserService
def initialize(user_attributes)
@user_attributes = user_attributes
end
def call
puts "Creating user with following attributes.."
p @user_attributes
end
end