Sha256: 3c293fa5eb35ca65ad7ce4889d1eb238ac3a5a8fd013847849c6ae3210f5e9bf

Contents?: true

Size: 637 Bytes

Versions: 9

Compression:

Stored size: 637 Bytes

Contents

module Pallets
  module Util
    extend self

    def generate_id(str)
      initials = str.gsub(/[^A-Z]+([A-Z])/, '\1')[0,3]
      random = SecureRandom.hex(5)
      "#{initials}#{random}"
    end

    def constantize(str)
      names = str.split('::')

      # Raise the "usual" NameError
      Object.const_get(str) if names.empty?

      # Handle "::Const" cases
      names.shift if names.first.empty?

      names.inject(Object) do |constant, name|
        if constant.const_defined?(name, false)
          constant.const_get(name, false)
        else
          constant.const_missing(name)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pallets-0.11.0 lib/pallets/util.rb
pallets-0.10.0 lib/pallets/util.rb
pallets-0.9.0 lib/pallets/util.rb
pallets-0.8.0 lib/pallets/util.rb
pallets-0.7.0 lib/pallets/util.rb
pallets-0.6.0 lib/pallets/util.rb
pallets-0.5.1 lib/pallets/util.rb
pallets-0.5.0 lib/pallets/util.rb
pallets-0.4.0 lib/pallets/util.rb