Class: Cathode::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cathode/base.rb

Overview

Holds the top-level Cathode accessors for defining an API.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.tokens_requiredObject (readonly)

Returns the value of attribute tokens_required.



33
34
35
# File 'lib/cathode/base.rb', line 33

def tokens_required
  @tokens_required
end

Class Method Details

.define(&block) ⇒ Object

Defines an API

Parameters:

  • block

    The API’s versions and resources, defined using this class’s ‘version`, `resources`, and `resource` methods



38
39
40
# File 'lib/cathode/base.rb', line 38

def define(&block)
  instance_eval(&block)
end

.require_tokensObject

Configures this API to require incoming requests to have a valid token



85
86
87
# File 'lib/cathode/base.rb', line 85

def require_tokens
  @tokens_required = true
end

.resource(resource_name, params = nil, &block) ⇒ Object

Defines a singular resource on version 1.0.0 of the API

Parameters:

  • resource_name (Symbol)

    The resource’s name

  • params (Hash) (defaults to: nil)

    Optional params, e.g. ‘{ actions: :all }`

  • block

    A block defining the resource’s actions and properties, run inside the context of version 1.0.0 with access to the methods in the ActionDsl and ResourceDsl



66
67
68
69
70
# File 'lib/cathode/base.rb', line 66

def resource(resource_name, params = nil, &block)
  version 1 do
    resource resource_name, params, &block
  end
end

.resources(resource_name, params = nil, &block) ⇒ Object

Defines a plural resource on version 1.0.0 of the API

Parameters:

  • resource_name (Symbol)

    The resource’s name

  • params (Hash) (defaults to: nil)

    Optional params, e.g. ‘{ actions: :all }`

  • block

    A block defining the resource’s actions and properties, run inside the context of version 1.0.0 with access to the methods in the ActionDsl and ResourceDsl



78
79
80
81
82
# File 'lib/cathode/base.rb', line 78

def resources(resource_name, params = nil, &block)
  version 1 do
    resources resource_name, params, &block
  end
end

.version(version_number, &block) ⇒ Object

Defines a new version

Parameters:

  • version_number (String, Fixnum, Float)

    A number or string representing a SemVer-compliant version number. If a ‘Fixnum` or `Float` is passed, it will be converted to a string before being evaluated for SemVer compliance, so passing `1.5` is equivalent to passing `’1.5.0’‘.

  • block

    A block defining the version’s resources and actions, and has access to the methods in the ActionDsl and ResourceDsl



56
57
58
# File 'lib/cathode/base.rb', line 56

def version(version_number, &block)
  Version.define(version_number, &block)
end

.versionsCathode::ObjectCollection

Lists the collection of versions associated with this API

Returns:



44
45
46
# File 'lib/cathode/base.rb', line 44

def versions
  Version.all
end