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 'rails_helper' | |
RSpec.describe Stateful do | |
let(:model_class) do | |
Struct.new(:status, :saved, :scopes, :running_at, :finished_at, :finished_count, :privileged) do | |
include Stateful | |
def self.scope(*args) | |
define_singleton_method(args.first) {} | |
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
# Mark an ActiveRecord model as having a state machine. | |
# The state of the model defaults to being stored on an attribute | |
# called `state` or can be specified via the `column` arg to | |
# the `stateful` call. To set the default state for a | |
# class, set a default column value for `state` in the database | |
# or use `initial: true` when defining the initial state. | |
# | |
# Use Symbols for all keys and values in state definitions. | |
module Stateful |
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
with assessment_block_index as ( | |
select | |
entity_key as assessment_block_key, | |
parent_key as step_key | |
from entity_indices | |
where entity_type = 'AssessmentBlock' | |
), | |
step_index as ( | |
select | |
entity_key as step_key, |
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
has_one :intro_progress, inverse_of: :skill_progress, autosave: true, required: false, dependent: :destroy | |
has_one :video_challenge_progress, inverse_of: :skill_progress, autosave: true, required: false, dependent: :destroy | |
has_many :step_progresses, -> { includes(:step).order(:order) }, inverse_of: :skill_progress, autosave: true, | |
dependent: :destroy |
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 Instructify | |
# Mark an ActiveRecord model as having a state machine. Requires a | |
# string attribute called `state`. To set the default state for a | |
# class, set a default column value for `state` in the database. | |
# | |
# Use Symbols for all keys and values in state definitions. | |
module Stateful | |
ANY = Object.new |
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 OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def google_oauth2 | |
auth = request.env['omniauth.auth'] | |
manager = Manager.where(provider: auth['provider'], uid: auth['uid']) | |
.first_or_initialize(email: auth['info']['email']) | |
manager.first_name = auth['info']['first_name'] | |
manager.last_name = auth['info']['last_name'] | |
manager.save! |
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 create | |
self.resource = resource_class.send_confirmation_instructions(resource_params) | |
yield resource if block_given? | |
render_resource(resource, blueprint: :admin) | |
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
// In express middleware when a request comes in we start a transaction | |
// and store it in continuation local store (think thread local store) | |
// Create a new user in the DB and return the newly created User instance | |
let user = await User.create({name: "Sally Smith", email: "[email protected]"}); | |
user.setAddressStreet1("123 Main St."); // With no Typescript | |
user.addressStreet1 = "123 Main St."; // If we introduce Typescript this would be okay too |
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 'faraday' | |
require 'faraday_middleware' | |
require 'active_support/all' | |
def period(app_id, start_date, end_date) | |
date = start_date | |
results = [] | |
while date <= end_date do | |
results << { date: date.strftime("%F"), dau: day(app_id, date) } | |
date = (date + 1) |
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 PullUpErrors | |
extend ActiveSupport::Concern | |
# Used to pull up errors that are on an associated collection or object | |
included do | |
after_validation :pull_up_errors | |
def pull_up_errors(*attrs) | |
@pull_up_attrs = Array(attrs) |
NewerOlder