satynos
2008-Dec-17 18:16 UTC
config.reload_plugins = true is not picking up all the changes
Currently I am tweaking resources_controller plugin to fit to our need, I changed all the references of require to require_dependency so that Rails will take care of whether to use require or load dependening on the environment. I heard that even in development environment, rails is not going to reload the plugins even though I use require_dependency unless I set config.reload_plugins = true. At first, I was very much excited, to see that Rails is in deed reloading the files (Constants) and this is a very good news, because I can see the changes I make to the plugins without restarting the server everytime. Unfortunately my excitement didnot last very long when I see that Rails is reloading all the files under the lib folder of the plugin except the init.rb and my first reference to the Plugin. For instance, resources_controller defined the following in init.rb: require_dependency ''ardes/resources_controller'' ActionController::Base.send :extend, Ardes::ResourcesController Andres::ResourcesController (Module) resides in resources_controller.rb under lib/andres/ folder. Apart from this file (I call it Plugin Core file) and init.rb, there are bunch of other files under lib/andres/resources_controller folder. Where appropriate I included require_dependency instead of require. For some reason (that I can''t figure out yet) Rails is reloading all the other files except init.rb and resources_controller.rb If someone can shed light I would appreciate it. <b>Related Information:</b> Resources_Controller Plugin Folder Structure: vendor/plugins/resources_controller/init.rb vendor/plugins/resources_controller/andres/resources_controller.rb vendor/plugins/resources_controller/andres/resources_controller/ actions.rb vendor/plugins/resources_controller/andres/resources_controller/ helper.rb vendor/plugins/resources_controller/andres/resources_controller/ named_route_helper.rb vendor/plugins/resources_controller/andres/resources_controller/ singleton_actions.rb vendor/plugins/resources_controller/andres/resources_controller/ specification.rb Contents of resources_controller.rb (Plugin Core File) require_dependency ''ardes/resources_controller/specification'' require_dependency ''ardes/resources_controller/include_actions'' require_dependency ''ardes/resources_controller/actions'' require_dependency ''ardes/resources_controller/singleton_actions'' require_dependency ''ardes/resources_controller/helper'' require_dependency ''ardes/resources_controller/named_route_helper'' module Ardes#:nodoc: module ResourcesController mattr_accessor :actions, :singleton_actions self.actions = Ardes::ResourcesController::Actions self.singleton_actions Ardes::ResourcesController::SingletonActions def self.extended(base) base.class_eval do class_inheritable_reader :resource_specification_map write_inheritable_attribute(:resource_specification_map, {}) end end def resources_controller_for(name, options = {}, &block) options.assert_valid_keys (:class, :source, :singleton, :actions, :in, :find, :load_enclosing, :route, :segment, :as, :only, :except) when_options = {:only => options.delete(:only), :except => options.delete(:except)} #unless included_modules.include? Ardes::ResourcesController::InstanceMethods class_inheritable_reader :specifications, :route_name hide_action :specifications, :route_name extend Ardes::ResourcesController::ClassMethods include Ardes::ResourcesController::InstanceMethods helper Ardes::ResourcesController::Helper include Ardes::ResourcesController::NamedRouteHelper #end before_filter(:load_enclosing_resources, when_options) unless load_enclosing_resources_filter_exists? #before_filter :some_action before_filter :load_resources, :only => [:index] before_filter :load_resource, :only => [:show, :edit, :update, :destroy] before_filter :build_resource, :only => [:new, :create] write_inheritable_attribute(:specifications, []) specifications << ''*'' unless options.delete(:load_enclosing) =false unless (actions = options.delete(:actions)) == false actions ||= options[:singleton] ? Ardes::ResourcesController.singleton_actions : Ardes::ResourcesController.actions include_actions actions, when_options end route = (options.delete(:route) || name).to_s name = options[:singleton] ? name.to_s : name.to_s.singularize write_inheritable_attribute :route_name, options[:singleton] ? route : route.singularize nested_in(*options.delete(:in)) if options[:in] write_inheritable_attribute(:resource_specification, Ardes::ResourcesController::Specification.new(name, options, &block)) end # Creates a resource specification mapping. Use this to specify how to find an enclosing resource that # does not obey usual rails conventions. Most commonly this would be a singleton resource. # # See Specification#new for details of how to call this def map_enclosing_resource(name, options = {}, &block) spec = Ardes::ResourcesController::Specification.new(name, options, &block) resource_specification_map[spec.segment] = spec end # this will be deprecated soon as it''s badly named - use map_enclosing_resource def map_resource(*args, &block) map_enclosing_resource(*args, &block) end # Include the specified module, optionally specifying which public methods to include, for example: # include_actions ActionMixin, :only => :index # include_actions ActionMixin, :except => [:create, :new] def include_actions(mixin, options = {}) mixin.extend(Ardes::ResourcesController::IncludeActions) unless mixin.respond_to?(:include_actions) mixin.include_actions(self, options) end private def load_enclosing_resources_filter_exists? if respond_to?(:find_filter) # BC 2.0-stable branch find_filter(:load_enclosing_resources) else filter_chain.detect {|c| c.method == :load_enclosing_resources} end end end Thanks in advance. PS: I have observed the similar behaviour with other plugin too. -Satynos --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
satynos
2008-Dec-21 16:49 UTC
Re: config.reload_plugins = true is not picking up all the changes
Don''t worry about it. I finally figured it out. It looks like plugin methods that add funtionality to core modules (ActionController, ActiveRecord,..) will not be removed from the memory table though we say config.reload_plugins as the rails is not reloadable even in development mode. -Satynos On Dec 17, 1:16 pm, satynos <dharamgollap...@gmail.com> wrote:> Currently I am tweaking resources_controller plugin to fit to our > need, I changed all the references of require to require_dependency so > that Rails will take care of whether to use require or load > dependening on the environment. I heard that even in development > environment, rails is not going to reload the plugins even though I > use require_dependency unless I set config.reload_plugins = true. > > At first, I was very much excited, to see that Rails is in deed > reloading the files (Constants) and this is a very good news, because > I can see the changes I make to the plugins without restarting the > server everytime. Unfortunately my excitement didnot last very long > when I see that Rails is reloading all the files under the lib folder > of the plugin except the init.rb and my first reference to the Plugin. > For instance, resources_controller defined the following in init.rb: > > require_dependency ''ardes/resources_controller'' > ActionController::Base.send :extend, Ardes::ResourcesController > > Andres::ResourcesController (Module) resides in > resources_controller.rb under lib/andres/ folder. Apart from this file > (I call it Plugin Core file) and init.rb, there are bunch of other > files under lib/andres/resources_controller folder. Where appropriate > I included require_dependency instead of require. For some reason > (that I can''t figure out yet) Rails is reloading all the other files > except init.rb and resources_controller.rb > > If someone can shed light I would appreciate it. > > <b>Related Information:</b> > Resources_Controller Plugin Folder Structure: > vendor/plugins/resources_controller/init.rb > vendor/plugins/resources_controller/andres/resources_controller.rb > vendor/plugins/resources_controller/andres/resources_controller/ > actions.rb > vendor/plugins/resources_controller/andres/resources_controller/ > helper.rb > vendor/plugins/resources_controller/andres/resources_controller/ > named_route_helper.rb > vendor/plugins/resources_controller/andres/resources_controller/ > singleton_actions.rb > vendor/plugins/resources_controller/andres/resources_controller/ > specification.rb > > Contents of resources_controller.rb (Plugin Core File) > require_dependency ''ardes/resources_controller/specification'' > require_dependency ''ardes/resources_controller/include_actions'' > require_dependency ''ardes/resources_controller/actions'' > require_dependency ''ardes/resources_controller/singleton_actions'' > require_dependency ''ardes/resources_controller/helper'' > require_dependency ''ardes/resources_controller/named_route_helper'' > > module Ardes#:nodoc: > module ResourcesController > mattr_accessor :actions, :singleton_actions > self.actions = Ardes::ResourcesController::Actions > self.singleton_actions > Ardes::ResourcesController::SingletonActions > > def self.extended(base) > base.class_eval do > class_inheritable_reader :resource_specification_map > write_inheritable_attribute(:resource_specification_map, > {}) > end > > end > > def resources_controller_for(name, options = {}, &block) > options.assert_valid_keys > (:class, :source, :singleton, :actions, :in, :find, :load_enclosing, :route, :segment, :as, :only, :except) > when_options = {:only => options.delete(:only), :except => > options.delete(:except)} > > #unless included_modules.include? > Ardes::ResourcesController::InstanceMethods > class_inheritable_reader :specifications, :route_name > hide_action :specifications, :route_name > extend Ardes::ResourcesController::ClassMethods > include Ardes::ResourcesController::InstanceMethods > helper Ardes::ResourcesController::Helper > include Ardes::ResourcesController::NamedRouteHelper > #end > > before_filter(:load_enclosing_resources, when_options) unless > load_enclosing_resources_filter_exists? > > #before_filter :some_action > > before_filter :load_resources, :only => [:index] > before_filter :load_resource, :only => > [:show, :edit, :update, :destroy] > before_filter :build_resource, :only => [:new, :create] > > write_inheritable_attribute(:specifications, []) > specifications << ''*'' unless options.delete(:load_enclosing) => false > > unless (actions = options.delete(:actions)) == false > actions ||= options[:singleton] ? > Ardes::ResourcesController.singleton_actions : > Ardes::ResourcesController.actions > include_actions actions, when_options > end > > route = (options.delete(:route) || name).to_s > name = options[:singleton] ? name.to_s : name.to_s.singularize > write_inheritable_attribute :route_name, options[:singleton] ? > route : route.singularize > > nested_in(*options.delete(:in)) if options[:in] > > write_inheritable_attribute(:resource_specification, > Ardes::ResourcesController::Specification.new(name, options, &block)) > end > > # Creates a resource specification mapping. Use this to specify > how to find an enclosing resource that > # does not obey usual rails conventions. Most commonly this would > be a singleton resource. > # > # See Specification#new for details of how to call this > def map_enclosing_resource(name, options = {}, &block) > spec = Ardes::ResourcesController::Specification.new(name, > options, &block) > resource_specification_map[spec.segment] = spec > end > > # this will be deprecated soon as it''s badly named - use > map_enclosing_resource > def map_resource(*args, &block) > map_enclosing_resource(*args, &block) > end > > # Include the specified module, optionally specifying which public > methods to include, for example: > # include_actions ActionMixin, :only => :index > # include_actions ActionMixin, :except => [:create, :new] > def include_actions(mixin, options = {}) > mixin.extend(Ardes::ResourcesController::IncludeActions) unless > mixin.respond_to?(:include_actions) > mixin.include_actions(self, options) > end > > private > def load_enclosing_resources_filter_exists? > if respond_to?(:find_filter) # BC 2.0-stable branch > find_filter(:load_enclosing_resources) > else > filter_chain.detect {|c| c.method > == :load_enclosing_resources} > end > end > end > > Thanks in advance. > PS: I have observed the similar behaviour with other plugin too. > > -Satynos--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---