Skip to content

Instantly share code, notes, and snippets.

def product_scope
variants_associations = [{ option_values: :option_type }, {images_for_variant: {variant_images: :image}}, :default_price, :prices, :images, { variant_description: :description }]
if current_api_user.has_spree_role?("admin")
scope = Spree::Product.with_deleted.accessible_by(current_ability, :read)
.includes(:product_properties, {:option_types => :option_values}, variants: variants_associations, master: variants_associations)
unless params[:show_deleted]
scope = scope.not_deleted
end
else
source 'https://rubygems.org'
#############################
# Environment-agnostic gems #
#############################
gem 'rails', '4.0.0'
gem 'rack-cors', :require => 'rack/cors' # cross-domain request support for rack
gem 'pg' # postgres database client
gem 'sass-rails', '~> 4.0.0' # Use SCSS for stylesheets
##
# This is spree 2-1-stable specific logic to re-apply a promotion code. It will not work for 2-2-stable because promotions are being revamped.
# https://github.com/spree/spree/issues/4398
#
def reapply_coupon_codes
codes = []
# Go through the adjustments to find promotions that are not eligible
adjustments.each do |a|
if a.eligible == false && a.originator.respond_to?(:promotion) && a.originator.promotion.code
@HoyaBoya
HoyaBoya / x.rb
Last active August 29, 2015 13:58
Print "helloworld" with the following if/else statement.
# PROBLEM
# Find an implementation of "x" that will force the code below to print "helloworld".
# SOLUTION
# This doesn't work with threads forked to return true/false. The trick is to just have x do both.
def x
print "hello"
false
end
@HoyaBoya
HoyaBoya / reverse_linked_list.rb
Created April 8, 2014 14:37
Reverse a Singley Linked List
# PROBLEM:
# Given a singley linked list, reverse the list.
#
# SOLUTION:
# Nothing to tricky other to keep track of all the pointers when iterating through.
# Basic object to represent a linked list.
class Node
attr_accessor :next
attr_accessor :value
module Middleware
class VersionEndpoint
def initialize(app)
@app = app
end
def call(env)
# Return the latest git-sha in ENV if the request is exactly the version endpoint.
if env['PATH_INFO'] == '/version'
if version = source_version
@HoyaBoya
HoyaBoya / .json
Last active March 26, 2024 21:22
crmls_lim_create_example
{
"acknowledgedWarnings": [
"string"
],
"listing": {
"core": {
"uid": "string",
"cumulativeDaysOnMarket": 0,
"daysOnMarket": 0,
"previousStandardStatus": "string",
This file has been truncated, but you can view the full file.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:6.0.36
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------