Class: SmilyCli::Resource

Inherits:
Struct
  • Object
show all
Defined in:
lib/smily_cli/resource.rb

Overview

A single API v3 resource the CLI knows about by name: the command word the user types (rentals), the HTTP path it maps to (rentals, or booking/discount_codes), the singular label for help text, and grouping metadata used by smily resources.

Anything not in the Registry is still reachable through smily api, so the registry is about ergonomics and discoverability, not a hard gate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def command
  @command
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def description
  @description
end

#groupObject

Returns the value of attribute group

Returns:

  • (Object)

    the current value of group



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def group
  @group
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def path
  @path
end

#readonlyObject

Returns the value of attribute readonly

Returns:

  • (Object)

    the current value of readonly



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def readonly
  @readonly
end

#singularObject

Returns the value of attribute singular

Returns:

  • (Object)

    the current value of singular



11
12
13
# File 'lib/smily_cli/resource.rb', line 11

def singular
  @singular
end

Instance Method Details

#collection_pathString

Path to the collection endpoint (e.g. "rentals").

Returns:

  • (String)


31
32
33
# File 'lib/smily_cli/resource.rb', line 31

def collection_path
  path
end

#member_path(id) ⇒ String

Path to a member endpoint (e.g. "rentals/42").

Parameters:

  • id (String, Integer)

Returns:

  • (String)


38
39
40
# File 'lib/smily_cli/resource.rb', line 38

def member_path(id)
  "#{path}/#{id}"
end

#resource_keyString

The JSON:API top-level key used in request/response bodies for this resource. For v3 this is the pluralized resource name, i.e. the last path segment (booking/discount_codes -> discount_codes).

Returns:

  • (String)


20
21
22
# File 'lib/smily_cli/resource.rb', line 20

def resource_key
  path.split("/").last
end

#writable?Boolean

Returns whether write commands (create/update/delete) apply.

Returns:

  • (Boolean)

    whether write commands (create/update/delete) apply



25
26
27
# File 'lib/smily_cli/resource.rb', line 25

def writable?
  !readonly
end