lib/restspec/schema/schema.rb in restspec-0.1 vs lib/restspec/schema/schema.rb in restspec-0.2

- old
+ new

@@ -8,10 +8,14 @@ attr_reader :name # The set of attributes that conforms the schema. attr_reader :attributes + # TODO: Document + attr_accessor :intention + attr_accessor :original_schema + # @param name [Symbol] The name of the schema # @return a new {Restspec::Schema::Schema Schema} object def initialize(name) self.name = name self.attributes = {} @@ -21,9 +25,17 @@ # This shouldn't be used without cloning first, to avoid modifying a schema # used elsewhere. def extend_with(without: []) without.each { |attribute_name| attributes.delete(attribute_name.to_s) } self + end + + def attributes_for_intention + return attributes if intention.blank? + + attributes.inject({}) do |hash, (name, attribute)| + attribute.can?(intention) ? hash.merge(name => attribute) : hash + end end private attr_writer :name, :attributes