Chad Thatcher
2007-Feb-02 21:53 UTC
Need help making a "system wide" config object available
I need to make a config object (a static, unchanging object created preferably at the application level) available to not only certain models but other housekeeping objects as well. I have a config object that is created once and remains in that state for its entire life so I want to be able to access this object everywhere where I need it as it is quite large and recreating it more than once in the same process would be wasteful. So far I am instantiating it in application.rb but is this the right place? How can I refer to the main application object from within a model? What is the best way of getting at this object? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
apsoto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-03 17:27 UTC
Re: Need help making a "system wide" config object available
I do something similar to the following: config/config.rb: module Config CONFIG = { :config_value_1 => "some string", :config_object_1 => SomeObject.new } end then in your environment.rb just: require ''config'' Then in your code you could: include Config then CONFIG[:config_value_1] where you need the config values in your code. However, there is no concept of a ''shared'' config across all your mongrel processes for example, each process would have it''s own copy of the config. I suppose you could try something using memcached or similar to share things across procs. On Feb 2, 1:53 pm, Chad Thatcher <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I need to make a config object (a static, unchanging object created > preferably at the application level) available to not only certain > models but other housekeeping objects as well. > > I have a config object that is created once and remains in that state > for its entire life so I want to be able to access this object > everywhere where I need it as it is quite large and recreating it more > than once in the same process would be wasteful. > > So far I am instantiating it in application.rb but is this the right > place? > > How can I refer to the main application object from within a model? > What is the best way of getting at this object? > > Thanks. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chad Thatcher
2007-Feb-03 18:25 UTC
Re: Need help making a "system wide" config object available
Thanks Alex, I only need for a single process where the config is reused in many places - I wanted to avoid loading it over and over in the same page hit. So what you have suggested looks good and I''ll have a go. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---