Skip to content

Instantly share code, notes, and snippets.

Avatar

Ismael Celis ismasan

View GitHub Profile
View type_identities.rb
module Identities
TypeError = Class.new(ArgumentError)
class Nope
def matches?(_)
false
end
def call(value)
value
@ismasan
ismasan / field_policies.rb
Created Feb 11, 2020
Playing with composable value coercion policies
View field_policies.rb
Result = Struct.new('Result', :mode, :value) do
def pass
copy(:pass)
end
def halt
copy(:halt)
end
def copy(new_mode)
View parametric_nullable_types.rb
Parametric.policy(:nullable_integer) do
PARAMETRIC_INT_EXP = /^\d+$/.freeze
coerce do |value, _key, _context|
if value.to_s =~ PARAMETRIC_INT_EXP
value.to_i
else
nil
end
end
@ismasan
ismasan / validations_for.rb
Created Jun 26, 2019
Declarative AM validations depending on arbitrary attributes
View validations_for.rb
# class Page
# include ValidationsFor
#
# validations_for page_type: 'offer' do
# validates :amount, presence: true
# end
#
# validations_for page_type: 'page' do
# validates :title, presence: true
# end
View inventory_control.mkd

Bodegas default

Para integrar ecommerce <-> inventario.

  • world
  • ecommerce
  • sales
done evento Bootic Transferencia de inventario
View _unit_price.html
{% if product.has_multiple_prices or product.price.positive %}
<span class="bootic-price">{{ product.price.format }}</span>
<span class="bootic-price-comparison-box" style="display: {% if product.has_price_comparison %}inline-block{% else %}none{% endif %}">
<span class="bootic-price-comparison-label">{{ 'products.price_comparison_label' | t }}</span>
<strike class="bootic-price-comparison">
{% if product.has_price_comparison %}
{{ product.price_comparison.format }}
{% endif %}
</strike>
View crea_o_actualiza_variante.rb
# Carga el producto
product = shop.product(id: variante_bsale[“booticProductId”])
# revisa si ya existe una variante con el nombre
variante_existente = product.variants.find{|v| v.title == nombre_variante }
# si ya existe, actualízala
if variante_existente
variant = variante_existente.update_variant(
sku: variante_bsale[‘code’],
@ismasan
ismasan / images.rb
Last active Sep 28, 2018
Download all product images for a Bootic shop
View images.rb
require 'open-uri'
require 'fileutils'
## USAGE
# S=<subdominio> bootic runner images.rb
#
subdomain = ENV.fetch('S')
s = root.all_shops(subdomains: subdomain).first
prs = s.products(status: 'all').full_set
shop_dir = File.join(".", subdomain)
View object_mapper.js
var sys = require('util');
function value (obj, path) {
var segments = path.split('/')
if(segments[0] == '') segments = segments.slice(1)
return segments.reduce(function (memo, segment) {
return (typeof memo == 'object') ? memo[segment] : {}
}, obj)
}
@ismasan
ismasan / bootic_images_upload.rb
Last active Mar 8, 2018
Importa imágenes desde una directorio a productos con el mismo nombre
View bootic_images_upload.rb
# asume un directorio ./imgs/ junto a este script
# correr con
# SUBDOMAIN=acme bootic runner bootic_images_upload.rb
# sólo importa a productos con este tag
TAG = 'import20171115'.freeze
def errors(errs)
errs.map{|e| [e.field, e.messages.first].join(': ')}
end
You can’t perform that action at this time.