Skip to content

Instantly share code, notes, and snippets.

View midas's full-sized avatar

Jason Harrelson midas

View GitHub Profile
@midas
midas / app_subdomain.rb
Created December 6, 2012 05:01
Rails router constraints
class AppSubdomain
def self.matches?( request )
request.subdomain == 'app'
end
end
def SomeClass
# do something
end
defmodule User do
...
@always_required ~w(email encrypted_password)a
@password_reset_allowed ~w(password new_password new_password_confirmation)a
@password_reset_required @always_required + ~w(password new_password)a
def password_reset_changeset(user, attrs) do
user
|> cast(atrs, @password_reset_allowed)
|> validate_required(@password_reset_required)
@midas
midas / user.ex
Last active November 8, 2018 21:55
def insert_changeset(user \\ %__MODULE__{}, attrs) do
user
|> cast(attrs, ~w(email password password_confirmation)a
|> validate_required(~w(email password password_confimation)a)
|> generate_identifier()
end
def update_changeset(user, attrs) do
user
|> cast(attrs, ~w(email name)a)
@midas
midas / user.ex
Last active November 8, 2018 21:40
def changeset(struct \\ %__MODULE__{}, attrs) do
user
|> cast(attrs, ~w(email password password_confirmation)a
|> validate_required(~w(email password password_confimation)a)
|> generate_identifier()
end
defp generate_identifier(changeset) do
identifier = UUID.uuid1()
Ecto.Changeset.put_change(changeset, :identifier, identifier)
def registration_changeset(user \\ %__MODULE__{}, attrs) do
user
|> cast(attrs, ~w(email password password_confirmation)a
|> validate_required(~w(email password password_confimation)a)
|> generate_identifier()
end
def profile_update_changeset(user, attrs) do
user
|> cast(attrs, ~w(email name)a