repo_name stringlengths 6 97 | path stringlengths 3 341 | text stringlengths 8 1.02M |
|---|---|---|
daniel-sim/common | lib/pr/common/version.rb | <filename>lib/pr/common/version.rb
module PR
module Common
VERSION = '0.3.8'
end
end
|
daniel-sim/common | app/jobs/shop_update_job.rb | <gh_stars>0
class ShopUpdateJob < PR::Common::ApplicationJob
def perform(params)
with_analytics do
shop = Shop.find_by(shopify_domain: params[:shop_domain])
# ensure we have a user
PR::Common::UserService
.new
.find_or_create_user_by_shopify(email: params[:webhook][:email], shop... |
daniel-sim/common | db/migrate/20181008151650_add_provider_to_users.rb | class AddProviderToUsers < ActiveRecord::Migration[5.0]
def change
# prevent this migration failing for apps that already have a
# provider on users
return if column_exists? :users, :provider
add_column :users, :provider, :integer
end
end
|
daniel-sim/common | db/migrate/20180920132700_add_uninstalled_to_shops.rb | class AddUninstalledToShops < ActiveRecord::Migration[5.0]
def change
# prevent this migration failing for apps that already have an
# uninstalled on shops
return if column_exists? :shops, :uninstalled
add_column :shops, :uninstalled, :boolean, null: false, default: false
end
end
|
daniel-sim/common | spec/dummy/db/schema.rb | <filename>spec/dummy/db/schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the a... |
daniel-sim/common | app/controllers/admin/promo_codes_controller.rb | <reponame>daniel-sim/common
module Admin
class PromoCodesController < BaseController
def new
@promo_code = PR::Common::Models::PromoCode.new
end
def create
@promo_code = PR::Common::Models::PromoCode.new(promo_code_params)
@promo_code.created_by = current_admin
if @promo_code.sav... |
daniel-sim/common | lib/pr/common/configuration.rb | module PR
module Common
class Configuration
attr_accessor :signup_params, :send_welcome_email,
:send_confirmation_email, :referrer_redirect,
:pricing, :default_app_plan
attr_writer :pricing_method
# Symbol of method to call on ShopifyService or lambda.
... |
daniel-sim/common | db/migrate/20190514142223_common_add_created_by_to_promo_codes.rb | class CommonAddCreatedByToPromoCodes < ActiveRecord::Migration[5.0]
def change
add_reference :promo_codes, :created_by
end
end
|
daniel-sim/common | spec/models/shop_spec.rb | require "rails_helper"
RSpec.describe Shop, type: :model do
it { is_expected.to belong_to(:promo_code).optional }
describe ".with_active_charge" do
it "includes only shops with a user whose active charge is true" do
active_charge_shop = create(:shop, user: build(:user, active_charge: true))
inactiv... |
daniel-sim/common | spec/lib/pr/common/sustained_analytics_service_spec.rb | <reponame>daniel-sim/common
require "rails_helper"
describe PR::Common::SustainedAnalyticsService do
subject(:service) { described_class.new(shop, current_time: current_time) }
let!(:shop) { create(:shop, :with_user, shopify_plan: "basic", charged_at: current_time) }
let(:current_time_period) { shop.current_tim... |
daniel-sim/common | spec/lib/pr/common/session_promo_code_service_spec.rb | <filename>spec/lib/pr/common/session_promo_code_service_spec.rb
require "rails_helper"
describe SessionPromoCodeService do
subject(:service) { described_class.new(session) }
let(:code) { "THE-CODE" }
let(:promo_code) { PR::Common::Models::PromoCode.create(code: code) }
let(:shop) { create(:shop) }
let(:sess... |
daniel-sim/common | lib/pr/common/models/promo_code.rb | <reponame>daniel-sim/common
module PR
module Common
module Models
class PromoCode < ApplicationRecord
self.table_name = "promo_codes"
def self.model_name
ActiveModel::Name.new(self, nil, "PromoCode")
end
has_many :shops, class_name: "::Shop"
belongs_to :cr... |
daniel-sim/common | spec/factories/shops.rb | FactoryBot.define do
factory :shop do
sequence(:shopify_domain) { |n| "shop#{n}" }
shopify_token { "<PASSWORD>" }
shopify_plan { "affiliate" }
uninstalled { false }
trait :uninstalled do
uninstalled { true }
end
trait :cancelled do
shopify_plan { "cancelled" }
end
tr... |
daniel-sim/common | db/migrate/20190118074633_common_add_converted_to_paid_add_to_time_period.rb | <reponame>daniel-sim/common
class CommonAddConvertedToPaidAddToTimePeriod < ActiveRecord::Migration[5.0]
def change
add_column :time_periods, :converted_to_paid_at, :datetime
add_index :time_periods, :converted_to_paid_at
end
end
|
daniel-sim/common | lib/tasks/pr/common_tasks.rake | <reponame>daniel-sim/common
namespace 'common' do
namespace 'webhooks' do
desc "Recreate all webhooks based on config. Optionally pass a comma-separated list of domains."
task :recreate, [:shops_file] => [:environment] do |_, args|
FileUtils.mkdir_p(Rails.root.join('tmp'))
Rails.logger = Logger.ne... |
daniel-sim/common | config/initializers/sidekiq.rb | require 'sidekiq'
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == [ENV['sidekiq_admin_login'], ENV['sidekiq_admin_password']]
end
|
daniel-sim/common | app/controllers/sessions_controller.rb | <reponame>daniel-sim/common
class SessionsController < ApiBaseController
skip_before_action :authenticate_user_from_token!
def create
auth_key = Devise.authentication_keys.first
@user = User.find_for_database_authentication(auth_key => signin_params[auth_key])
if @user && @user.valid_password?(signin_... |
daniel-sim/common | lib/pr/common/webhook_service.rb | <gh_stars>0
module PR
module Common
class WebhookService
# Recreates all webhooks and returns a list of any that failed
def self.recreate_webhooks!(shops = Shop.installed)
shops.find_each.map do |shop|
new(shop).recreate_webhooks! || shop.shopify_domain
end.reject { |item| it... |
daniel-sim/common | spec/lib/pr/common/user_service_spec.rb | <reponame>daniel-sim/common<gh_stars>0
require "rails_helper"
describe PR::Common::UserService do
describe "#find_or_create_user_by_shopify" do
subject(:service) { PR::Common::UserService.new }
let(:shop) { create(:shop) }
context "when user exists" do
let(:user) { create(:user, username: "shopify... |
daniel-sim/common | lib/pr/common/engine.rb | <filename>lib/pr/common/engine.rb
require 'rack-affiliates'
require 'sidekiq'
module PR
module Common
class Engine < ::Rails::Engine
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_bot, dir: 'spec/factories'
end
initializer :append_migrations do |a... |
daniel-sim/common | spec/lib/pr/common/webhook_service_spec.rb | require "rails_helper"
describe PR::Common::WebhookService do
let(:shop) { create(:shop) }
let(:uninstalled_shop) { create(:shop, :uninstalled) }
let(:existing_api_webhooks) do
[
OpenStruct.new(
id: 1,
address: "https://localhost:3000/webhooks/shop_update",
topic: "shop/update",... |
daniel-sim/common | pr-common.gemspec | $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require 'pr/common/version'
Gem::Specification.new do |s|
s.name = "pr-common"
s.version = PR::Common::VERSION
s.licenses = ['MIT']
s.authors = ["Pemberton Rank Ltd"]
s.email = ["<EMAIL>"]
s.homepage = "... |
daniel-sim/common | lib/pr/common/sign_in_service.rb | <reponame>daniel-sim/common
module PR
module Common
# Generic sign in service. To be filled out further later
module SignInService
def self.track(shop)
Rails.logger.info "Shop signed in. shop_id=#{shop.id}"
user = shop.user
properties = { email: user.email, promo_code: shop.promo... |
daniel-sim/common | db/migrate/20180922164900_drop_application_charges.rb | <filename>db/migrate/20180922164900_drop_application_charges.rb
class DropApplicationCharges < ActiveRecord::Migration[5.0]
def change
# prevent this migration failing for apps that don't have have an
# application_charges table
return unless table_exists? :application_charges
drop_table :application... |
daniel-sim/common | db/migrate/20181009124306_add_charged_at_to_users.rb | <filename>db/migrate/20181009124306_add_charged_at_to_users.rb
class AddChargedAtToUsers < ActiveRecord::Migration[5.0]
def change
return if column_exists? :users, :charged_at
add_column :users, :charged_at, :datetime
end
end
|
daniel-sim/common | config/initializers/shopify_app.rb | <reponame>daniel-sim/common
# Non-Shopify apps can use Common so just try to configure here and fail gracefully if no ShopifyApp configuration provided
ShopifyApp.try (:configure) do |config|
# For non-common, application specific webhooks be sure to do config.webhooks.push() rather than overwriting those here
# TO... |
daniel-sim/common | app/controllers/passwords_controller.rb | class PasswordsController < ApiBaseController
skip_before_action :authenticate_user_from_token!
def update
@user = User.reset_password_by_token(change_password_params.merge(reset_password_token: params[:id]))
if @user && @user.errors.empty?
@user.update_attribute(:confirmed, true)
render json: ... |
daniel-sim/common | spec/lib/pr/common/sign_in_service_spec.rb | <reponame>daniel-sim/common<filename>spec/lib/pr/common/sign_in_service_spec.rb
require "rails_helper"
describe PR::Common::SignInService do
let(:shop) { create(:shop, :with_user) }
let(:user) { shop.user }
describe ".track" do
it "sends tracking analytics" do
expect(Analytics)
.to receive(:ide... |
daniel-sim/common | spec/dummy/db/migrate/20180903181059_add_fields_from_users.rb | <reponame>daniel-sim/common
class AddFieldsFromUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :active_charge, :boolean, default: false
add_column :users, :shop_id, :integer
end
end
|
daniel-sim/common | lib/pr/common.rb | require "pr/common/version"
require "pr/common/engine"
require "pr/common/configuration"
require "pr/common/shopify_errors"
require "pr/common/tokenable"
require "pr/common/token_authenticable"
require "pr/common/affiliate_redirect"
require "pr/common/models/application_record"
require "pr/common/models/user"
require "... |
daniel-sim/common | app/jobs/app_uninstalled_job.rb | class AppUninstalledJob < PR::Common::ApplicationJob
def perform(params)
with_analytics do
shop = Shop.find_by(shopify_domain: params[:shop_domain])
PR::Common::ShopifyService
.new(shop: shop)
.update_shop(shopify_plan: shop.shopify_plan, uninstalled: true)
end
end
end
|
daniel-sim/common | lib/pr/common/models/user.rb | <gh_stars>0
module PR
module Common
module Models
# This is a stake in the ground to gradually improve our messy User code
# As much as possible should be in Common
# We will work towards this by including this module in our apps and moving generic pieces here
# So please include PR::Commo... |
daniel-sim/common | spec/support/factory_bot.rb | RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
FactoryBot.definition_file_paths = %w(spec/factories)
FactoryBot.find_definitions
|
daniel-sim/common | spec/lib/pr/common/models/time_period_spec.rb | <reponame>daniel-sim/common<gh_stars>0
require "rails_helper"
describe PR::Common::Models::TimePeriod do
let(:user) { create(:user) }
it do
is_expected.to define_enum_for(:kind)
.with_values %i[installed reinstalled reopened
uninstalled closed]
end
context "when newly created"... |
daniel-sim/common | app/controllers/promo_codes_controller.rb | <reponame>daniel-sim/common<filename>app/controllers/promo_codes_controller.rb<gh_stars>0
class PromoCodesController < ApplicationController
STATUS_VALID = "valid".freeze
STATUS_ERROR = "error".freeze
def check
service = ParamsPromoCodeService.new(params)
render json: response_json(service)
end
pri... |
daniel-sim/common | db/migrate/20190514130737_common_add_value_to_promo_codes.rb | class CommonAddValueToPromoCodes < ActiveRecord::Migration[5.0]
def change
add_column :promo_codes, :value, :decimal, precision: 5, scale: 2, default: 100.0, null: false
end
end
|
daniel-sim/common | db/migrate/20180912223800_add_referrer_to_users.rb | class AddReferrerToUsers < ActiveRecord::Migration[5.0]
def change
# prevent this migration failing for apps that already have a
# referrer on users
return if column_exists? :users, :referrer
add_column :users, :referrer, :string
end
end
|
daniel-sim/common | app/controllers/admin/base_controller.rb | <filename>app/controllers/admin/base_controller.rb
module Admin
class BaseController < ActionController::Base
layout "admin"
before_action :authenticate_admin!
end
end
|
daniel-sim/common | lib/pr/common/session_promo_code_service.rb | <filename>lib/pr/common/session_promo_code_service.rb
class SessionPromoCodeService
KEY = :promo_code
def initialize(session)
@session = session
end
def maybe_apply_to_shop(shop)
return unless redeemable?
PR::Common::Models::PromoCode.transaction do
return unless redeemable? # check again n... |
daniel-sim/common | app/jobs/pr/common/sustained_analytics_job.rb | <filename>app/jobs/pr/common/sustained_analytics_job.rb<gh_stars>0
module PR
module Common
class SustainedAnalyticsJob < ApplicationJob
queue_as :low_priority
def perform
with_analytics { PR::Common::SustainedAnalyticsService.perform }
end
end
end
end
|
daniel-sim/common | lib/pr/common/models/admin.rb | require "devise"
module PR
module Common
module Models
class Admin < ApplicationRecord
extend Devise::Models
devise :database_authenticatable, :validatable, :rememberable
self.table_name = "admins"
has_many :promo_codes,
class_name: "PR::Common::Models::Pr... |
daniel-sim/common | spec/dummy/db/migrate/20180829195156_create_shop.rb | class CreateShop < ActiveRecord::Migration[5.2]
def change
create_table :shops do |t|
t.string :plan_name
t.string :shopify_domain
t.string :shopify_token, null: false
end
end
end
|
daniel-sim/common | spec/jobs/shop_update_job_spec.rb | <reponame>daniel-sim/common
require "rails_helper"
describe ShopUpdateJob do
let(:shopify_domain) { "the_domain" }
let(:shop) { create(:shop, shopify_domain: shopify_domain, user: build(:user)) }
let(:service) { PR::Common::ShopifyService.new(shop: shop) }
let(:plan) { "the_plan" }
let(:email) { "<EMAIL>" }
... |
daniel-sim/common | db/migrate/20190514090235_common_create_promo_codes.rb | class CommonCreatePromoCodes < ActiveRecord::Migration[5.0]
def change
create_table :promo_codes do |t|
t.column :code, :string, null: false, unique: true, index: true
t.column :description, :string
t.timestamps
end
end
end
|
daniel-sim/common | lib/pr/common/controller_concerns/promo_codes.rb | <filename>lib/pr/common/controller_concerns/promo_codes.rb
module PR
module Common
module PromoCodes
extend ActiveSupport
def maybe_reconcile_promo_codes(shop)
maybe_remove_existing_promo_code(shop)
maybe_apply_promo_code(shop)
end
private
# We only want to remove ... |
daniel-sim/common | lib/pr/common/models/shop.rb | <filename>lib/pr/common/models/shop.rb
require "shopify_app/shop"
require "shopify_app/session_storage"
module PR
module Common
module Models
module Shop
PLAN_FROZEN = "frozen".freeze
PLAN_CANCELLED = "cancelled".freeze
PLAN_LOCKED = "locked".freeze
PLAN_AFFILIATE = "affiliat... |
daniel-sim/common | db/migrate/20181009084529_make_plan_name_nullable.rb | class MakePlanNameNullable < ActiveRecord::Migration[5.0]
def change
change_column_null :shops, :plan_name, true
end
end
|
daniel-sim/common | lib/pr/common/models/time_period.rb | <reponame>daniel-sim/common<gh_stars>0
module PR
module Common
module Models
# Shops have multiple time periods.
# Time periods may not overlap.
#
# When a new shop is created:
# - a new TimePeriod should be created with start_time NOW(), end_time NULL, and kind :installed
#
... |
daniel-sim/common | spec/factories/time_periods.rb | <filename>spec/factories/time_periods.rb
FactoryBot.define do
factory :time_period, class: PR::Common::Models::TimePeriod do
trait :installed do
kind { :installed }
end
trait :reinstalled do
kind { :reinstalled }
end
trait :reopened do
kind { :reopened }
end
trait :uni... |
daniel-sim/common | spec/lib/pr/common/shopify_service_spec.rb | <gh_stars>0
require "rails_helper"
describe PR::Common::ShopifyService do
subject(:service) { described_class.new(shop: shop) }
let(:user) { build(:user) }
let(:shop) { create(:shop, app_plan: "foobar", user: user) }
let(:promo_code) { PR::Common::Models::PromoCode.create(code: "THE_CODE", value: 50.0) }
d... |
daniel-sim/common | spec/dummy/app/models/shop.rb | <reponame>daniel-sim/common
class Shop < ApplicationRecord
include PR::Common::Models::Shop
has_one :user
end
|
daniel-sim/common | db/migrate/20190118073208_common_add_app_plan_to_shops.rb | class CommonAddAppPlanToShops< ActiveRecord::Migration[5.0]
def change
add_column :shops, :app_plan, :string
add_index :shops, :app_plan
end
end
|
daniel-sim/common | lib/pr/common/affiliate_redirect.rb | <gh_stars>0
module PR
module Common
class AffiliateRedirect
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
@request = Rack::Request.new(env)
return handle_referral if referrer?
[status, headers, body]
end
... |
daniel-sim/common | lib/pr/common/charge_service.rb | module PR
module Common
class ChargeService
def self.determine_app_plan_from_charge(charge)
PR::Common.config.pricing.detect { |price| price[:name] == charge.name }&.[](:key)
end
def initialize(shop)
@shop = shop
@user = shop.user
end
def create_charge(price... |
daniel-sim/common | db/migrate/20180915214900_add_plan_name_to_shops.rb | class AddPlanNameToShops < ActiveRecord::Migration[5.0]
def change
# prevent this migration failing for apps that already have a
# plan_name on shops
return if column_exists? :shops, :plan_name
add_column :shops, :plan_name, :string
end
end
|
daniel-sim/common | lib/pr/common/sustained_analytics_service.rb | <reponame>daniel-sim/common<filename>lib/pr/common/sustained_analytics_service.rb
class PR::Common::SustainedAnalyticsService
DAYS_BETWEEN_SHOP_RETAINED_ANALYTIC = Rails.env.staging? ? 1 : 7
DAYS_UNTIL_PAYMENT_CHARGED = Rails.env.staging? ? 1 : 30
# Strictly speaking, this should depend on the trial_days of vari... |
daniel-sim/common | app/controllers/webhooks_controller.rb | class WebhooksController < ShopifyApp::WebhooksController
def receive
# Backwards-compatible uninstalled webhook at /webhooks/.
# Can be removed later.
if webhook_type.blank? && request.headers['HTTP_X_SHOPIFY_TOPIC'] == 'app/uninstalled'
params[:type] = 'app_uninstalled'
end
super
end
... |
daniel-sim/common | spec/lib/pr/common/models/promo_code_spec.rb | <gh_stars>0
require "rails_helper"
describe PR::Common::Models::PromoCode do
subject(:promo_code) { described_class.new(code: "oneTwoThree") }
it { is_expected.to have_many :shops }
it { is_expected.to validate_presence_of :code }
it { is_expected.to validate_numericality_of(:value).is_greater_than_or_equal_t... |
daniel-sim/common | app/controllers/forgotten_password_requests_controller.rb | <filename>app/controllers/forgotten_password_requests_controller.rb
class ForgottenPasswordRequestsController < ApiBaseController
skip_before_action :authenticate_user_from_token!
def create
# with providers like Shopify, users can have the same email address
# in future we should aim to move all authentic... |
daniel-sim/common | app/jobs/shop_update_reconcile_job.rb | <reponame>daniel-sim/common<filename>app/jobs/shop_update_reconcile_job.rb
class ShopUpdateReconcileJob < PR::Common::ApplicationJob
queue_as :low_priority
def self.enqueue
Shop.installed.with_active_plan.pluck(:id).each(&method(:perform_later))
end
def perform(shop_id)
# Set this back to the beginnin... |
daniel-sim/common | app/controllers/signups_controller.rb | <reponame>daniel-sim/common
class SignupsController < ApiBaseController
skip_before_action :authenticate_user_from_token!
before_action :generate_anonymous
# this method risks getting very messy
# when we work on it next we should think about what the responsibility of this method is-
# - register a user, re... |
daniel-sim/common | lib/pr/common/shopify_errors.rb | module PR
module Common
module ShopifyErrors
def self.convert(exception, shopify_domain = nil)
return exception if shopify_domain.blank?
case exception
when ActiveResource::ClientError
return convert_from_client_error(exception, shopify_domain)
when ActiveResource:... |
daniel-sim/common | app/controllers/shops_controller.rb | <gh_stars>0
class ShopsController < ApplicationController
def callback
shop = Shop.find_by(shopify_domain: shop_params[:myshopify_domain])
PR::Common::ShopifyService
.new(shop: shop)
.update_shop(shopify_plan: shop_params[:plan_name], uninstalled: shop.uninstalled)
end
private
def shop_pa... |
daniel-sim/common | spec/dummy/config/initializers/common_initializer.rb | PR::Common.configure do |config|
config.signup_params = %i[email website password <PASSWORD>]
config.send_welcome_email = false
config.send_confirmation_email = false
config.referrer_redirect = 'http://localhost:3000/login'
config.pricing = [
{
key: :staff_business_free,
price:... |
daniel-sim/common | spec/lib/pr/common/charge_service_spec.rb | <reponame>daniel-sim/common<filename>spec/lib/pr/common/charge_service_spec.rb
require "rails_helper"
# See spec/dummy/config/initializers/common_initializer.rb for
# test pricing
describe PR::Common::ChargeService do
let(:user) { create(:user) }
let(:shop) { create(:shop, user: user) }
let(:base_url) { "http://... |
daniel-sim/common | config/initializers/analytics_ruby.rb | <gh_stars>0
Analytics = Segment::Analytics.new(
write_key: ENV.fetch("segment_write_key", ""),
on_error: proc { |status, msg| print msg }
)
|
daniel-sim/common | db/migrate/20190116102258_common_create_time_periods.rb | <gh_stars>0
class CommonCreateTimePeriods < ActiveRecord::Migration[5.0]
def change
create_table :time_periods do |t|
t.column :start_time, :datetime, null: false, default: -> { "NOW()" }, index: true
t.column :end_time, :datetime, index: true
t.integer :kind, default: 0, null: false, index: tru... |
daniel-sim/common | spec/jobs/app_uninstalled_job_spec.rb | require 'rails_helper'
describe AppUninstalledJob do
let(:shop) { create(:shop, user: build(:user)) }
before { allow(Analytics).to receive(:flush) }
describe "#perform" do
it "set the shop to uninstalled" do
expect { described_class.perform_now(shop_domain: shop.shopify_domain) }
.to change {... |
daniel-sim/common | lib/pr/common/user_service.rb | module PR
module Common
class UserService
def find_or_create_user_by_shopify(email:, shop:, referrer: nil)
find_shopify_user(shop: shop, referrer: referrer) ||
create_shopify_user(email: email, shop: shop, referrer: referrer)
end
private
def create_shopify_user(email:, ... |
daniel-sim/common | db/migrate/20190116101646_common_remove_reinstalled_at_and_reopened_at_from_shops.rb | <filename>db/migrate/20190116101646_common_remove_reinstalled_at_and_reopened_at_from_shops.rb
class CommonRemoveReinstalledAtAndReopenedAtFromShops < ActiveRecord::Migration[5.0]
def change
remove_column :shops, :reinstalled_at, :timestamp
remove_column :shops, :reopened_at, :timestamp
end
end
|
daniel-sim/common | spec/lib/pr/common/params_promo_code_service_spec.rb | require "rails_helper"
describe ParamsPromoCodeService do
subject(:service) { described_class.new(params) }
let(:code) { "THE-CODE" }
let(:promo_code) { PR::Common::Models::PromoCode.create(code: code) }
let(:params) { { promo_code: code } }
describe "#record" do
before { promo_code }
it "returns ... |
daniel-sim/common | lib/pr/common/shopify_service.rb | module PR
module Common
class ShopifyService
def initialize(shop:)
@shop = shop
@user = @shop.user
end
def update_user(email:)
@user.update(email: email)
end
def update_shop(options = {})
# This method used to explicitly require "shopify_plan" and "u... |
daniel-sim/common | db/migrate/20190213214625_common_add_no_brainer_indices.rb | class CommonAddNoBrainerIndices < ActiveRecord::Migration[5.0]
def change
unless ActiveRecord::Base.connection.index_exists?(:shops, :shopify_domain)
add_index :shops, :shopify_domain
end
unless ActiveRecord::Base.connection.index_exists?(:users, :username)
add_index :users, :username
end... |
daniel-sim/common | db/migrate/20190520170125_common_add_expires_at_to_promo_codes.rb | <gh_stars>0
class CommonAddExpiresAtToPromoCodes < ActiveRecord::Migration[5.0]
def change
add_column :promo_codes, :expires_at, :timestamp
end
end
|
daniel-sim/common | lib/pr/common/params_promo_code_service.rb | class ParamsPromoCodeService
KEY = :promo_code
def initialize(params)
@params = params
end
def record
@record ||= PR::Common::Models::PromoCode.find_by(code: code)
end
def error
return "Invalid promo code." unless record
"Promo code expired." unless record.redeemable?
end
def code
... |
daniel-sim/common | app/controllers/charges_controller.rb | class ChargesController < ApplicationController
include ShopifyApp::LoginProtection
before_action :login_again_if_different_shop
around_action :shopify_session
before_action :load_user
def create
price = charge_service.up_to_date_price[:price]
charge = charge_service.create_charge(price, request.bas... |
daniel-sim/common | lib/pr/common/tokenable.rb | <reponame>daniel-sim/common
module PR
module Common
module Tokenable
extend ActiveSupport::Concern
included do
after_create :update_access_token!
def update_access_token!
self.access_token = "#{self.id}:#{Devise.friendly_token}"
save
end
end
end
... |
daniel-sim/common | spec/dummy/config/application.rb | require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
require "pr/common"
module Dummy
class Application < Rails::Application
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
# Throws an error unless this is set
Rails.applica... |
daniel-sim/common | spec/jobs/shop_update_reconcile_job_spec.rb | require "rails_helper"
describe ShopUpdateReconcileJob do
let(:shop) { create(:shop, user: build(:user)) }
let(:sustained_analytics_service) { PR::Common::SustainedAnalyticsService.new(shop) }
around do |example|
Timecop.freeze(Time.new(2019, 1, 1, 5, 28, 31).in_time_zone) { example.run }
end
before do... |
daniel-sim/common | spec/requests/shop_spec.rb | require "rails_helper"
describe "Shop" do
let(:shopify_domain) { "the_domain" }
let(:shop) { create(:shop, shopify_domain: shopify_domain) }
let(:service) { PR::Common::ShopifyService.new(shop: shop) }
let(:plan) { "some new plan" }
describe "POST shops/callback" do
let(:url) { "/shops/callback" }
... |
daniel-sim/common | config/initializers/shopify_rate_limiting.rb | # https://docs.shopify.com/api/introduction/api-call-limit
module ActiveResource
# 429 Client Error
class RateLimitExceededError < ClientError # :nodoc:
end
class Connection
@@mutex = Mutex.new
RATE_LIMIT_SLEEP_SECONDS = ENV["RATE_LIMIT_SLEEP_SECONDS"] || 20 # number of seconds to sleep (by sleeping ... |
daniel-sim/common | db/migrate/20181204125450_add_reinstalled_at_to_shops.rb | class AddReinstalledAtToShops < ActiveRecord::Migration[5.0]
def change
return if column_exists? :shops, :reinstalled_at
add_column :shops, :reinstalled_at, :timestamp
end
end
|
daniel-sim/common | db/migrate/20190118122037_common_add_monthly_usd_to_time_periods.rb | class CommonAddMonthlyUsdToTimePeriods < ActiveRecord::Migration[5.0]
def change
add_column :time_periods, :monthly_usd, :decimal, default: 0, null: false
end
end
|
daniel-sim/common | app/controllers/api_base_controller.rb | <filename>app/controllers/api_base_controller.rb
class ApiBaseController < ActionController::Base
require 'active_model_serializers'
include PR::Common::TokenAuthenticable
end
|
daniel-sim/common | app/helpers/admin_form_helper.rb | module AdminFormHelper
def form_group(model, value_key, &block)
content_tag(:div,
[capture(&block), form_group_error(model, value_key)].compact.join.html_safe,
class: form_group_class(model, value_key))
end
def form_group_class(model, value_key)
return "form-group" if mode... |
daniel-sim/common | app/jobs/pr/common/application_job.rb | <filename>app/jobs/pr/common/application_job.rb
module PR
module Common
class ApplicationJob < ActiveJob::Base
def with_analytics
yield
Analytics.flush
end
end
end
end
|
xavriley/synthdef | lib/synthdef/parser.rb | <reponame>xavriley/synthdef
require 'bindata'
class PascalString < BinData::Primitive
uint8 :len, :value => lambda { data.length }
string :data, :read_length => :len
def get; self.data; end
def set(v) self.data = v; end
end
class SynthInt < BinData::Choice
endian :big
default_parameter :selection => ... |
xavriley/synthdef | spec/spec_helper.rb | require 'pry'
require 'synthdef'
|
xavriley/synthdef | lib/synthdef.rb | <filename>lib/synthdef.rb
require "synthdef/version"
require "synthdef/graphviz"
require "synthdef/parser"
class Synthdef
def self.read(*args)
Parser.read(*args)
end
def self.has_params?(sdef, param_list)
sdef = sdef.snapshot # ensure we cast to Ruby types, not bindata types
param_list.map!(&:to_s)... |
xavriley/synthdef | spec/synthdef_spec.rb | require 'spec_helper'
require 'active_support'
describe Synthdef do
let(:synthdef_binary) { IO.read(File.expand_path("../data/recorder.scsyndef", __FILE__)) }
let(:complex_synthdef_binary) { IO.read(File.expand_path("../data/hoover.scsyndef", __FILE__)) }
it 'reads a basic version 1 synthdef' do
parsed_synt... |
xavriley/synthdef | lib/synthdef/graphviz.rb | module Graphviz
def graphviz
self[:synthdefs].each do |sdef|
%Q{
digraph synthdef {
#{generate_node_info(sdef)}
#{generate_node_connections(sdef)}
}
}.trim
end
end
def generate_node_info(sdef)
sdef[:ugens].each do |ug|
case ug[:ugen_name]
when "Control"... |
nnikolov96/toy_robot | lib/toy_robot/simulator.rb | <reponame>nnikolov96/toy_robot<filename>lib/toy_robot/simulator.rb<gh_stars>0
module ToyRobot
class Simulator
attr_reader :robot
def initialize(table)
@table = table
end
def place(east, north, facing)
return unless @table.valid_location?(east, north)
@robot = Robot.new(east, n... |
nnikolov96/toy_robot | spec/toy_robot_spec.rb | RSpec.describe ToyRobot do
end
|
nnikolov96/toy_robot | lib/toy_robot/table.rb | module ToyRobot
class Table
def initialize(width, length)
@width = width
@length = length
end
def valid_location?(east, north)
(0...@width).cover?(east) && (0...@length).cover?(north)
end
end
end |
nnikolov96/toy_robot | spec/toy_robot/simulator_spec.rb | <gh_stars>0
require 'spec_helper'
RSpec.describe ToyRobot::Simulator do
let(:table) { ToyRobot::Table.new(5, 5) }
subject { ToyRobot::Simulator.new(table) }
it 'places the robot onto a valid position' do
expect(ToyRobot::Robot).to receive(:new)
.with(0, 0, 'NORTH')
.and_return(double)
subject... |
Flatiron-group/tenant_verification | app/controllers/reviews_controller.rb | class ReviewsController < ApplicationController
def index
review = Review.all
render json: review
end
def show
id = params[:id]
review = Review.find(id)
render json: review
end
def create
# param keys may subject to change depending on the body of the p... |
Flatiron-group/tenant_verification | db/seeds.rb | <reponame>Flatiron-group/tenant_verification<filename>db/seeds.rb
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.cre... |
Flatiron-group/tenant_verification | app/controllers/sessions_controller.rb | class SessionsController < ApplicationController
def create
user = Landlord.find_by(email: params[:email])
if user && user.authenticate(params[:password])
user_id = user.id
token = JWT.encode({user_id: user_id}, ENV['SECRET_TOKEN'])
render json: {token: token}
else
render json: {e... |
Flatiron-group/tenant_verification | test/controllers/tenents_controller_test.rb | require 'test_helper'
class TenentsControllerTest < ActionDispatch::IntegrationTest
test "should get show" do
get tenents_show_url
assert_response :success
end
test "should get create" do
get tenents_create_url
assert_response :success
end
test "should get update" do
get tenents_update_... |
Flatiron-group/tenant_verification | app/controllers/addresses_controller.rb | class AddressesController < ApplicationController
def index
address = Address.all
render json: address
end
def show
id = params[:id]
address = Address.find(id)
render json: address
end
def new
address = Address.new
render json: address
end... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.