lib/grape/reload/grape_api.rb in grape-reload-0.0.4 vs lib/grape/reload/grape_api.rb in grape-reload-0.1.0
- old
+ new
@@ -33,10 +33,16 @@
end
end
module Grape
module Reload
+ module EndpointPatch
+ def clear_inheritable_settings!
+ @inheritable_settings.clear
+ end
+ end
+
module AutoreloadInterceptor
extend ActiveSupport::Concern
def add_head_not_allowed_methods_and_options_methods(*args, &block)
self.class.skip_declaration = true
@@ -61,21 +67,37 @@
super(*args, &block)
end
METHOD
end
- def reinit!
- declaration = class_declaration.dup
+ def fire_definitions!
+ @declaration_cache.each {|decl|
+ send(decl[0],*deep_reconstantize.call(decl[1]),&decl[2])
+ }
+
+ endpoints.each { |e|
+ if e.options[:app].respond_to?('fire_definitions!')
+ e.options[:app].inheritable_setting.inherit_from(e.options[:app].inheritable_setting.parent)
+ e.options[:app].fire_definitions!
+ end
+
+ }
+ end
+
+ def reinit!(root = true)
+ @declaration_cache = class_declaration.dup
@class_decl = []
endpoints_cache = endpoints
reset!
- endpoints_cache.each { |e| e.options[:app].reinit! if e.options[:app].respond_to?('reinit!') }
-
- declaration.each {|decl|
- send(decl[0],*deep_reconstantize.call(decl[1]),&decl[2])
+ inheritable_setting.clear!
+ top_level_setting.clear!
+ endpoints_cache.each { |e|
+ e.inheritable_setting.clear!
+ e.options[:app].reinit!(false) if e.options[:app].respond_to?('reinit!')
}
change!
+ fire_definitions! if root
end
def recursive_!
end
@@ -101,12 +123,31 @@
end
end
end
end
+module Grape
+ module Util
+ class InheritableSetting
+ def clear!
+ self.route = {}
+ self.api_class = {}
+ self.namespace = InheritableValues.new # only inheritable from a parent when
+ # used with a mount, or should every API::Class be a seperate namespace by default?
+ self.namespace_inheritable = InheritableValues.new
+ self.namespace_stackable = StackableValues.new
+
+ self.point_in_time_copies = []
+
+ # self.parent = nil
+ end
+ end
+ end
+end
+
+
Grape::API.singleton_class.class_eval do
alias_method :inherited_shadowed, :inherited
- alias_method :settings_shadowed, :settings
def inherited(*args)
inherited_shadowed(*args)
args.first.class_eval do
include Grape::Reload::AutoreloadInterceptor
end
\ No newline at end of file