Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Haskins bearded-avenger

View GitHub Profile
View sidekiq.rake
namespace :sidekiq do
desc "Clear queued jobs in Sidekiq and reset all stats"
task :reset => :environment do
Sidekiq::Queue.all.each &:clear
Sidekiq::Stats.new.reset
Sidekiq::RetrySet.new.clear
Sidekiq::ScheduledSet.new.clear
end
end
View webhooks_controller.rb
class TenantWebhooksBraintreeController < ApplicationController
protect_from_forgery :except => :process_webhook
skip_before_action :verify_authenticity_token
before_action :verify_event
require 'pp'
def process_webhook
case @event.kind
View paypal.rb
module TenantServices
class SubscriptionServicePaypal
def initialize(params)
@subscription = params[:subscription]
@coupon = params[:coupon]
@paypal_token = params[:paypal_token]
@plan = @subscription.subscription_plan
@customer = @subscription.customer
@site = @subscription.site
View checkout.rb
module TenantServices
class CheckoutService
def initialize(params)
@site = params[:site]
@cart = params[:cart]
@customer = params[:customer]
@coupon_code = params[:coupon_code]
@selected_country = params[:selected_country]
View customer_notification.rb
class CustomerNotification < ApplicationRecord
belongs_to :site
belongs_to :customer
belongs_to :notifyable, polymorphic: true
acts_as_tenant :site
validates_uniqueness_to_tenant :customer_id, scope: [:notifyable_id, :notifyable_type]
end
View customer.rb
class Customer < ApplicationRecord
has_many :following_playlists, class_name:'PlaylistFollower', dependent: :destroy
def follow_playlist!(playlist_id)
following_playlists.create(playlist_id: playlist_id)
end
def unfollow_playlist!(playlist_id)
following_playlists.find_by(playlist_id: playlist_id).destroy
View playlist.rb
class Playlist < ApplicationRecord
belongs_to :site
belongs_to :customer
belongs_to :user
acts_as_tenant :site
validates_presence_of :title, :content
attr_accessor :spam_answer
View bookmarks_controller.rb
class BookmarksController < ApplicationController
BOOKMARKABLES = {
'Course' => Course,
'Lesson' => Lesson,
'Post' => Post,
'LiveStream' => LiveStream,
'Download' => Download,
'Project' => Project,
'Exercise' => Exercise,
View access_service.rb
module TenantServices
class AccessService
def initialize(params)
@site = params[:site]
@customer = params[:customer]
@user = params[:user]
@record = params[:record]
@feature = params[:feature]
View giftcard.rb
class GiftCard < ApplicationRecord
belongs_to :site
belongs_to :subscription_plan, optional: true
acts_as_tenant :site
include ProductConcern
include ImageUploader[:image]
enum status: { draft:0, published:1}