This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry-validation' | |
## Schema | |
Users::NewSchema = Dry::Validation.Form do | |
GENDERS = %w( | |
male | |
female | |
non-specific | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry-validation' | |
schema = Dry::Validation.Schema do | |
GENDERS = %w( | |
male | |
female | |
non-specific | |
) | |
required(:email).filled(:str?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Order | |
# Service Object used to transit order into checkout state | |
class CheckoutOrderService | |
def initialize(order) | |
@order = order | |
end | |
def call | |
validate_order! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassWithModule | |
include ModuleExample | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Abstract calculator class, only for inheritance | |
class Calculator | |
def calculate | |
raise NotImplementedError, 'must be implemented in subclass' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(number) | |
if (number % 3 == 0 && number % 5 ==0) | |
puts "FizzBuzz" | |
elsif (number % 3 == 0) | |
puts "Fizz" | |
elsif (number % 5 == 0) | |
puts "Buzz" | |
else | |
puts number | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SomeApp.Router do | |
use SomeApp.Web, :router | |
pipeline :browser do | |
plug :accepts, ["html"] | |
plug :fetch_session | |
plug :fetch_flash | |
plug :protect_from_forgery | |
plug :put_secure_browser_headers | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SomeApp.Endpoint do | |
use Phoenix.Endpoint, otp_app: :some_app | |
socket "/socket", SomeApp.UserSocket | |
# Serve at "/" the static files from "priv/static" directory. | |
# | |
# You should set gzip to true if you are running phoenix.digest | |
# when deploying your static files in production. | |
plug Plug.Static, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule BlogPostApp.Post do | |
use BlogPostApp.Web, :model | |
schema "posts" do | |
field :name, :string | |
field :content, :string | |
field :published, :boolean, default: false | |
timestamps() | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule BlogPostApp.Repo.Migrations.CreatePost do | |
use Ecto.Migration | |
def change do | |
create table(:posts) do | |
add :name, :string | |
add :content, :text | |
add :published, :boolean, default: false, null: false | |
timestamps() |
NewerOlder