Sha256: 8776c0887fa279172a1b17123850c7e5c51cb9f00afadafb806c5aa57959e59f

Contents?: true

Size: 625 Bytes

Versions: 4

Compression:

Stored size: 625 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)
          begin
            resource_name = JSONAPI::Resource._resource_name_from_type(type)
            Object.const_get resource_name if resource_name
          rescue NameError
            nil
          end
        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

4 entries across 4 versions & 1 rubygems

Version Path
jsonapi-resources-0.0.4 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.3 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.2 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.1 lib/jsonapi/resource_for.rb