class Textualize::RouteHashCreator
Public Instance Methods
create_route_hashes()
click to toggle source
# File lib/textualize/tasks/helpers/route_hash_creator.rb, line 9 def create_route_hashes json_from_gulp_task.fetch('resources').flat_map do |resource| create_method_hashes(resource) end end
Private Instance Methods
base_path()
click to toggle source
# File lib/textualize/tasks/helpers/route_hash_creator.rb, line 59 def base_path URI(json_from_gulp_task.fetch('baseUri')).path end
create_method_hashes(resource, relativeUri=nil)
click to toggle source
# File lib/textualize/tasks/helpers/route_hash_creator.rb, line 17 def create_method_hashes(resource, relativeUri=nil) relative_path = if relativeUri relativeUri + resource.fetch('relativeUri') else resource.fetch('relativeUri') end method_hashes = [] method_hashes += resource.fetch('methods').map do |method| method_hash = Hashie::Mash.new method_hash.verb = method.fetch('method') method_hash.url = base_path + relative_path method_hash.relative_path = relative_path method_hash.type = resource.fetch('type').keys.first method_hash.name = relative_path.split('/').last.gsub( /{|}|_id/, '' ) if method_hash.verb == 'post' method_hash.schema = method.fetch('body'). fetch('application/json'). fetch('schema') end if method.has_key?('securedBy') method_hash.secured_by = method.fetch('securedBy').first. fetch('oauth_2_0').fetch('scopes') end method_hash.merge!(transformed_response(method)) end if resource.has_key? 'resources' resource.fetch('resources').each do |nested_resource| method_hashes += create_method_hashes(nested_resource, relative_path) end end return method_hashes end
transformed_response(method_hash)
click to toggle source
# File lib/textualize/tasks/helpers/route_hash_creator.rb, line 63 def transformed_response(method_hash) response = method_hash.fetch('responses') case response.keys.first when '200' then ::Textualize::TwoHundred.new(response).transform when '204' then ::Textualize::TwoHundredFour.new(response).transform end end