Sha256: 0b767573d0f8bc89998ac0989a10bfeb258e54e406d6b1eaa0dab80de859bc4e

Contents?: true

Size: 768 Bytes

Versions: 28

Compression:

Stored size: 768 Bytes

Contents

module Lookbook
  module Utils
    class << self
      def id(*args)
        parts = args.map { |arg| arg.to_s }
        id_str = parts.join("-").force_encoding("UTF-8").parameterize.dasherize
        PathUtils.strip_slashes(id_str).tr("/", "-").gsub("--", "-")
      end

      def temp_id(prefix: nil)
        [prefix, (Time.now.to_f * 1000).to_i + rand(0..100)].compact.join("-")
      end

      def name(str)
        str.to_s.parameterize.tr("-", "_")
      end

      def symbolize_name(str)
        name(str).to_sym
      end

      def value_or_fallback(value, fallback = nil, &block)
        if value.nil?
          fallback_block = block || proc { fallback }
          fallback_block.call
        else
          value
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lookbook-2.3.4 lib/lookbook/support/utils/utils.rb
lookbook-2.3.3 lib/lookbook/support/utils/utils.rb
lookbook-2.3.2 lib/lookbook/support/utils/utils.rb
lookbook-2.3.0 lib/lookbook/support/utils/utils.rb
lookbook-2.2.2 lib/lookbook/support/utils/utils.rb
lookbook-2.2.1 lib/lookbook/support/utils/utils.rb
lookbook-2.2.0 lib/lookbook/support/utils/utils.rb
lookbook-2.1.1 lib/lookbook/support/utils/utils.rb
lookbook-2.1.0 lib/lookbook/support/utils/utils.rb
lookbook-2.0.5 lib/lookbook/support/utils/utils.rb
lookbook-2.0.4 lib/lookbook/support/utils/utils.rb
lookbook-2.0.3 lib/lookbook/support/utils/utils.rb
lookbook-2.0.2 lib/lookbook/support/utils/utils.rb
lookbook-2.0.1 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0.rc.3 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0.rc.2 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0.rc.1 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0.beta.9 lib/lookbook/support/utils/utils.rb
lookbook-2.0.0.beta.8 lib/lookbook/support/utils/utils.rb