lib/calamum/resource.rb in calamum-1.1.0 vs lib/calamum/resource.rb in calamum-1.2.0

- old
+ new

@@ -1,25 +1,34 @@ # This class represents a single resource. # It contains attributes from parsed definition. # So anywhere in view template we can use this object. class Calamum::Resource attr_accessor :uri, :action, :headers, - :auth, :params, :errors, :description, :response + :auth, :params, :errors, :description, :response, :tryit # Initialize object from attributes. # # @param attrs [Hash] attributes to set def initialize(attrs) @uri = attrs['uri'] @action = attrs['action'].upcase @headers = attrs['headers'] || {} - @auth = !!attrs['authentication'] + @auth = !attrs['authentication'] @params = attrs['params'] || {} @errors = attrs['errors'] || {} @description = attrs['description'] @response = attrs['response'] + @tryit = attrs['tryit'] end - + + # Returns a unique, but readable name for this resource suitable for use as a filename + # + # @return [String] resource filename + def slug + sanitized_uri = uri.gsub(/[^\w]/, '_').gsub('__', '_') + "#{sanitized_uri}_#{action.downcase}_#{self.object_id}" + end + # @override # Returns a string representing a label css class. # # @return [String] css class def action_label