Sha256: f0b1e7d8363d4c983e26c6512f7ace1ffaab6961ea25221aefdaaff452493c0e

Contents?: true

Size: 830 Bytes

Versions: 40

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

module WCC::Contentful::Helpers
  extend self

  def content_type_from_raw(value)
    case value.dig('sys', 'type')
    when 'Entry', 'DeletedEntry'
      value.dig('sys', 'contentType', 'sys', 'id')
    when 'Asset', 'DeletedAsset'
      'Asset'
    else
      raise ArgumentError, "Unknown content type '#{value.dig('sys', 'type') || 'null'}'"
    end
  end

  def constant_from_content_type(content_type)
    content_type.gsub(/[^_a-zA-Z0-9]/, '_').camelize
  end

  def shared_prefix(string_array)
    string_array.reduce do |l, s|
      l = l.chop while l != s[0...l.length]
      l
    end
  end

  def content_type_from_constant(const)
    return const.content_type if const.respond_to?(:content_type)

    name = const.try(:name) || const.to_s
    name.demodulize.camelize(:lower)
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
wcc-contentful-1.1.0 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.8 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.7 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.6 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.5 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.4 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.3 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.2 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.1 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.0 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.0.pre.rc3 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.0.pre.rc2 lib/wcc/contentful/helpers.rb
wcc-contentful-1.0.0.pre.rc1 lib/wcc/contentful/helpers.rb
wcc-contentful-0.4.0.pre.rc lib/wcc/contentful/helpers.rb
wcc-contentful-0.4.0.pre.beta lib/wcc/contentful/helpers.rb
wcc-contentful-0.4.0.pre.alpha lib/wcc/contentful/helpers.rb
wcc-contentful-0.3.0 lib/wcc/contentful/helpers.rb
wcc-contentful-0.3.0.pre.rc3 lib/wcc/contentful/helpers.rb
wcc-contentful-0.3.0.pre.rc2 lib/wcc/contentful/helpers.rb
wcc-contentful-0.3.0.pre.rc lib/wcc/contentful/helpers.rb