class Angus::ResourceDefinition
Public Class Methods
new(root_path, resource_name, representations)
click to toggle source
# File lib/angus/resource_definition.rb, line 6 def initialize(root_path, resource_name, representations) @root_path = root_path @resource_name = resource_name @resource_class_name = classify_resource(resource_name) @representations = representations || {} end
Public Instance Methods
build_response_metadata(response_representation)
click to toggle source
# File lib/angus/resource_definition.rb, line 38 def build_response_metadata(response_representation) return {} unless response_representation case response_representation when Angus::SDoc::Definitions::Representation result = [] response_representation.fields.each do |field| result << build_response_metadata(field) end result when Array result = [] response_representation.each do |field| result << build_response_metadata(field) end result else field_name = response_representation.name field_type_name = response_representation.type || response_representation.elements_type representation = representation_by_name(field_type_name) if representation.nil? field_name.to_sym else {field_name.to_sym => build_response_metadata(representation)} end end end
canonical_name()
click to toggle source
# File lib/angus/resource_definition.rb, line 17 def canonical_name Angus::String.underscore(@resource_class_name.to_s) end
operations()
click to toggle source
# File lib/angus/resource_definition.rb, line 13 def operations @representations.operations[@resource_name.to_s] || [] end
representation_by_name(name)
click to toggle source
TODO improve this find
# File lib/angus/resource_definition.rb, line 73 def representation_by_name(name) @representations.representations.find { |representation| representation.name == name } end
resource_class()
click to toggle source
# File lib/angus/resource_definition.rb, line 21 def resource_class return @resource_class if @resource_class require resource_path @resource_class = Object.const_get(@resource_class_name) end
resource_path()
click to toggle source
# File lib/angus/resource_definition.rb, line 28 def resource_path resource_path = File.join('resources', canonical_name) if @root_path.empty? resource_path else File.join(@root_path, resource_path) end end
Private Instance Methods
classify_resource(resource)
click to toggle source
# File lib/angus/resource_definition.rb, line 79 def classify_resource(resource) Angus::String.camelize(resource) end