Sha256: f446d2dfda8e95f13a8bde3831dd933534d7a7c61f0211d693bd47c6a15ce87c

Contents?: true

Size: 587 Bytes

Versions: 3

Compression:

Stored size: 587 Bytes

Contents

module JSONAPI
  module ResourceFor
    def self.included base
      base.extend ClassMethods
    end

    module ClassMethods
      if RUBY_VERSION >= '2.0'
        def resource_for(type)
          resource_name = JSONAPI::Resource._resource_name_from_type(type)
          Object.const_get resource_name if resource_name
        rescue NameError
          nil
        end
      else
        def resource_for(type)
          resource_name = JSONAPI::Resource._resource_name_from_type(type)
          resource_name.safe_constantize if resource_name
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jsonapi-resources-0.0.7 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.6 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.5 lib/jsonapi/resource_for.rb