lib/roda/endpoints/endpoint/class_interface.rb in roda-endpoints-0.1.0 vs lib/roda/endpoints/endpoint/class_interface.rb in roda-endpoints-0.2.0

- old
+ new

@@ -35,10 +35,19 @@ def inherited(child) child.attributes = attributes.dup child.defaults = defaults.dup child.statuses = statuses.dup child.verbs = verbs.dup + # child.verbs.each do |verb| + # key = "operations.#{child.type}.#{verb}" + # implementation = "operations.#{type}.#{verb}" + # container.register key do + # Endpoints.container.resolve implementation + # end + # end + child.transactions = transactions.dup + child.route(&@route_block) super end def ns @ns ||= name.gsub(/^Roda::Endpoints::/, '').underscore.tr('/', '.') @@ -47,28 +56,28 @@ # @return [Symbol] def type @type ||= Inflecto.underscore(Inflecto.demodulize(name)).to_sym end - # @param [Symbol] name + # @param [Symbol] verb # @param [Proc] block # @return [Symbol] name of the defined method - def verb(name, rescue_from: [], &block) + def verb(verb, rescue_from: [], &block) + self.verbs ||= superclass.verbs + (self.verbs += [verb]).freeze rescue_from = Array(rescue_from).flatten if rescue_from.any? block = proc do |*args| begin instance_exec(*args, &block) rescue *rescue_from Left($ERROR_INFO) end end end - define_method(name, &block) - container.register "operations.#{type}.#{name}", block - self.verbs ||= superclass.verbs - (self.verbs += [name]).freeze + define_method(verb, &block) + container.register "operations.#{type}.#{verb}", block end # @param [String, Symbol] key # @param [Proc] block # @@ -115,9 +124,11 @@ # @return [(Symbol, Hash, Proc)] def transactions @transactions ||= [] end + + attr_writer :transactions end end end end