Skip to content

Commit

Permalink
Add yard docs for ApipieBindings::Resource class (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmalloy authored and mbacovsky committed Jul 14, 2016
1 parent 8d21519 commit d285cb6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/apipie_bindings/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,65 @@ def initialize(name, api)
@api = api
end

# Execute an action on a resource
#
# @param action [Symbol]
# @param params [Hash]
# @param headers [Hash]
# @param options [Hash]
# @return [Hash]
def call(action, params={}, headers={}, options={})
@api.call(@name, action, params, headers, options)
end

# Get API documentation for a resource
#
# @return [Hash]
def apidoc
@api.apidoc[:docs][:resources][@name]
end

# Get list of all actions for a resource
#
# @return [Array<ApipieBindings::Action>]
def actions
apidoc[:methods].map { |a| action(a[:name].to_sym) }
end

# Determine if resource has a particular action
#
# @param name [Symbol] name of action to check
# @return [Bool]
def has_action?(name)
apidoc[:methods].any? { |action| action[:name].to_sym == name }
end

# Get ApipieBindings::Action
#
# @param name [Symbol] action name
# @return [ApipieBindings::Action]
def action(name)
ApipieBindings::Action.new(@name, name, @api)
end

# Get simiple string representation
#
# @return [String] ApipieBindings::Resource as a string
def singular_name
ApipieBindings::Inflector.singularize(@name.to_s)
end

# Get string representation
#
# @return [String] ApipieBindings::Resource as a string
def to_s
"<Resource :#{@name}>"
end

# Get string representation
#
# @return [String] ApipieBindings::Resource as a string
# @note same as to_s method
def inspect
to_s
end
Expand Down

0 comments on commit d285cb6

Please sign in to comment.