Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Kurtis Rainbolt-Greene krainboltgreene

🏠
Working from home
Block or report user

Report or block krainboltgreene

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View controllers.application\.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
View account.ex
defmodule Poutineer.Models.Account do
# ...
import Estate, only: [machine: 1]
# ...
machine([
onboarding_state: [complete: [converted: "completed"]],
role_state: [
grant_moderation_powers: [user: "moderator"],
grant_administrator_powers: [user: "administrator", moderator: "administrator"]
View amodel.ex
defmodule Amodel do
use Ecto.Schema
import Estate, only: [machine: 1]
machine([
onboarding_state: [
complete: [converted: "completed"]
],
role_state: [
View estate.ex
defmodule Estate do
defmacro machine(column_name, events) do
Enum.each(events, fn ({event_name, transitions}) ->
quote do
Enum.each(unquote(transitions), fn ({from, to}) ->
def unquote(:"before_#{event_name}")(%{unquote(column_name) => from} = record) do
record
end
def unquote(:"after_#{event_name}")(%{unquote(column_name) => to} = record) do
View create.ex
def create(_parent, arguments, _resolution) do
%{name: name, subject_id: subject_id} = arguments
tag = Repo.insert(Tag.changeset(%Tag{}, %{name: name}))
|> case do
{:ok, tag} -> tag
{:error, _} -> Repo.one(from(tag in Tag, where: tag.name == ^name))
end
subject_model = case arguments do
View gist:c71d8b98867036683a30ee5a9ecaa1dd
{:error,
#Ecto.Changeset<
action: :update,
changes: %{},
errors: [tags: {"is invalid", [type: {:array, :map}]}],
data: #Poutineer.Models.Recipe<>,
valid?: false
>}
View changeset.ex
post
|> Repo.preload(:tags)
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_assoc(:tags, [tag | post.tags])
|> Repo.update()
View response.json
{
"name": "kibana.mops.example.com",
"uuid": "0cf8c51c-2fd7-4090-ac1b-eb032a19041e",
"version": {
"number": "7.4.2",
"build_hash": "d7f39418dcaf7a243158b89f84bb82f39b04e5e5",
"build_number": 26506,
"build_snapshot": false
},
"status": {
View gist:e780e275d235720fd4b0252c2f22cb8f
module ActiveRecordStructuralOrAddition
def or!(other) # :nodoc:
raise
incompatible_values = structurally_incompatible_values_for_or(other)
unless incompatible_values.empty?
raise ArgumentError, "Relations passed to #or must be structurally compatible. Incompatible values: #{incompatible_values}"
end
self.where_clause = self.where_clause.or(other.where_clause)
self.having_clause = having_clause.or(other.having_clause)
View gist:694be83f3d6573a1cfc16786d511d6a9
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = tapeToJest;
var _imports = require("../utils/imports");
var _consts = require("../utils/consts");
You can’t perform that action at this time.