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
files = Dir.glob("db/migrate/*") | |
timestamps = files.collect{|f| f.split("/").last.split("_").first} | |
timestamps.count | |
migrations = ActiveRecord::Base.connection.execute("SELECT version FROM schema_migrations", as: :array).to_a.flatten | |
needs = timestamps - migrations | |
files_needs = files.select { |f| needs.include? f.split("/").last.split("_").first } | |
files_needs.sort.each do |f| | |
begin | |
require "#{Rails.root}/#{f}" | |
f.split('/').last.split('_')[1..-1].join('_').split('.').first.camelize.constantize.new.up |
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 import_supplier_products(path) | |
fail unless File.file? path | |
supplier_mappings = { | |
'224' => '372bd2a4-258d-48f3-9f84-598e1f09b657', | |
'445' => '0235c6b5-b399-40ad-91f3-cbe7b02ca565' | |
} | |
imported, failed = [], [] | |
CSV.foreach(path) do |row| | |
manufacturer = Registry::Manufacturer.find_or_create_by(name: row[3]) | |
sp = SupplierProduct.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
def import_retail_chain_products(path) | |
fail unless File.file? path | |
imported, failed = [], [] | |
retail_chain_id = 'ed45a234-1d88-481b-8bbd-1ff1ab8ff7a8' | |
mappings = { | |
code: { index: 0, type: :string }, | |
full_name: { index: 1, type: :string }, | |
short_name: { index: 2, type: :string }, | |
ru_international_name: { index: 6, type: :string }, | |
retail_chain_registry_concern_id: { index: 4, type: :registry, model: RetailChainRegistry::Concern }, |
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 'open-uri' | |
require 'nokogiri' | |
invoices = Invoice.where(contract_id: nil) | |
invoices.each do |invoice| | |
next if invoice.reload.contract | |
begin | |
xml_file = open(invoice.archive_file.file_url) | |
xml = Nokogiri::XML(xml_file) |
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 permitted_params(klass) | |
self_attrs = klass.accessible_attributes.reject { |attr| attr =~ /_attributes$/ }.map(&:to_sym) | |
nested_attrs = klass.nested_attributes_options.keys.map do |nested_klass| | |
nested_const_klass = nested_klass.to_s.singularize.classify.constantize | |
{ "#{nested_klass}_attributes".to_sym => permitted_params(nested_const_klass) } | |
end | |
types_attrs = klass.descendants.map { |type_class| permitted_params(type_class) } | |
(self_attrs + (types_attrs || []) + nested_attrs).flatten.uniq.compact | |
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
Show hidden characters
{ | |
"in_process_packages": | |
[ | |
], | |
"installed_packages": | |
[ | |
"Alignment", | |
"All Autocomplete", | |
"AngularJS", | |
"AngularJS (CoffeeScript)", |
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
!!cus = CloudUnit.where(slug: 'images', created_at: dates).joins(:items).group('cloud_units.id').having('COUNT(cloud_items.*) <= 1').to_a | |
!!cus.each { |unit| Resque.enqueue(Jobs::CloudImageCreator, unit.id) if unit.needs_processing? } | |
!!Component.where(cloud_unit_id: cus.map(&:id)).each { |c| c.box.boxings.each { |bb| bb.boxable.roulette_me } } |
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 Hash | |
def deep_diff(other) | |
(self.keys + other.keys).uniq.inject({}) do |memo, key| | |
left = self[key] | |
right = other[key] | |
next memo if left == right | |
if left.respond_to?(:deep_diff) && right.respond_to?(:deep_diff) | |
memo[key] = left.deep_diff(right) |
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 ActiveRecord::ConnectionAdapters::MysqlAdapter | |
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY" | |
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
d = Day.maximum(:date) | |
7.times { |i| Day.where(date: d - i.days).update_all(date: 7.days.from_now.to_date - i.days) } |
OlderNewer