Sha256: 85764ea0697f7072eda82bddb6a3504f4dc31184bba55c0f1a3e989fc7aea7cb

Contents?: true

Size: 619 Bytes

Versions: 6

Compression:

Stored size: 619 Bytes

Contents

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

    module ClassMethods
      # :nocov:
      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
      # :nocov:
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jsonapi-resources-0.0.13 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.12 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.11 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.10 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.9 lib/jsonapi/resource_for.rb
jsonapi-resources-0.0.8 lib/jsonapi/resource_for.rb