Sha256: 407927505b85eb9d20eb6ff5d3eb58a1bc9b15f8c4abdf079c00a089605f5b3f

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

require "attachment_helper/class_methods"
require "attachment_helper/version"

require 'uri'

module AttachmentHelper
  class << self
    attr_accessor :attachment_host

    def included(cls)
      cls.extend(AttachmentHelper::ClassMethods)
    end

    def attachment_host
      @attachment_host ||= 'http://please-set-attachment-host.com'
    end


    def symbolize_keys(hash)
      hash.each_with_object({}) {|kv, r| r[(kv.first.to_sym rescue kv.first)] = kv.last }
    end

    def get_url_by_path(path, options = {})
      return if path.nil?
      query = options.empty? ? '' : "?#{URI.encode_www_form(options)}"
      if path =~ /^http/
        "#{path}#{query}"
      else
        "#{AttachmentHelper.attachment_host}/#{path}#{query}"
      end
    end

    def get_filename_by_path(path)
      return if path.nil?
      path.split('/').last
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachment_helper-0.1.0 lib/attachment_helper.rb