Sha256: 8dbbfc0fbfe17dab0c6ee9e474a11573947452aed6cd2042ce71a250bedfead5
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
module JSONAPIonify::Api module Base::DocHelper Link = Struct.new(:title, :href) def self.extended(klass) klass.class_eval do extend JSONAPIonify::InheritedAttributes inherited_array_attribute :links end end def documentation_order(resources_in_order) @documentation_order = resources_in_order end def link(title, href) links << Link.new(title, href) end def title(title) @title = title end def description(description) @description = description end def documentation_output(request) #cache_store.fetch(resource_signature) do JSONAPIonify::Documentation.new(documentation_object(request)).result #end end def resources_in_order indexes = @documentation_order || [] resources.sort_by(&:name).sort_by do |resource| indexes.map(&:to_s).index(resource.type) || indexes.length end end def documentation_object(request) base_url = URI.parse(request.url).tap do |uri| uri.query = nil uri.path.chomp! request.path_info uri.path.chomp! '/docs' end.to_s OpenStruct.new( links: links, title: @title || self.name, base_url: base_url, description: JSONAPIonify::Documentation.render_markdown(@description || ''), resources: resources_in_order.map { |r| r.documentation_object base_url } ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jsonapionify-0.9.0 | lib/jsonapionify/api/base/doc_helper.rb |