Sha256: f5d7d02807699044aff0a341e3f08ed00397916270e2d627bd97cf9706c8d69a

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

#  gem build gvem.gemspec

require_relative "gvem/version"

ActiveRecord::Base.extend Gvem

module Gvem
  class Error < StandardError; end
  # Your code goes here...
  extend ActiveSupport::Concern

  def hola
    logger.debug "Hola Govani!  #{self.class.to_s.gsub("::", "_")}"
  end

  def show_errors
    if self.errors.count > 0
      logger.debug " =========== error #{self.model_name} ==========="
      self.errors.each do |attribute, error|
        logger.debug "#{attribute} => #{error}"
      end
      logger.debug " =========== /error ==========="
    end
  end

  def save_json(data = self, title = "", return_json = false)

    fecha = Time.now
    fecha = fecha.strftime('%Y/%m/%d')

    json_path = Rails.application.config.json_path + "#{json_path}/#{self.class.to_s.gsub("::", "_")}/#{fecha}"
    FileUtils.mkdir_p json_path, :mode => 0777

    json_file = "#{json_path}/#{title}_#{self[:id]}.json"

    #@redis.set(json_file, data.to_json)
    #logger.debug "====================================="
    # logger.debug @redis.get(json_file)

    #    redis.set(json_file, data.to_json )
    #logger.debug redis.get(json_file)

    parameter_file = File.new(json_file, "w")
    parameter_file.puts(data.to_json)
    parameter_file.close
    if return_json
      return data.to_json
    else
      return json_file
    end
  end

  def to_pdf(slug, method_json)
    doc = Pdf.find_by_slug(slug)
    file_json = self.public_send(method_json, slug)
    return "http://localhost:8083/pdf#{doc[:ruta]}?json_file=#{file_json}"
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gvem-0.1.2 lib/gvem.rb