Skip to content

Instantly share code, notes, and snippets.

View ghn's full-sized avatar

Germain ghn

  • Switzerland
View GitHub Profile
@ghn
ghn / service_return_value.rb
Last active September 4, 2024 09:39
What should be the value returned by a service?
# A - only returns success true/false
module DocumentService
class Create
def self.call(a, b)
if process_works?
true
else
false
end
end
@ghn
ghn / example.rb
Last active September 4, 2024 08:52
Rails service definition
# A
module Document
class ActionService
def initialize(a, b)
@a = a
@b = b
end
def call
compute
@ghn
ghn / app_form_builder.rb
Created April 28, 2023 11:18
Rails customs form Builder
# frozen_string_literal: true
# Inspiration: https://brandnewbox.com/notes/2021/03/form-builders-in-ruby/
#
# Example:
#
# f.input :field, options
#
# possible options:
# - as: symbol (:boolean, :data, :float, :radio, :select, :string, :text, :file, :time)