frankjmattia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-01 01:42 UTC
tweaking this to get a get a hash of namespaced models
so i have this piece of code here <code> Dir.glob(RAILS_ROOT + ''**/app/models/**/*.rb'').each do |file| @models.push file.gsub(%r{ ^#{RAILS_ROOT + ''/app/models/''}(.) }io, ''\1'').chomp(''.rb'') end </code> that gives me an array of all my models.. its something i tweaked from the current examples on getting recursive directory listings... except, it doesnt seem very rubyish... and doesnt return what I really want... what i want is some kind of way to have all my models and their associated namespaces in some kinda hash or array or something that i can use to refer to them in an administrationy menu... no, i don''t like hobo or autoadmin or streamlined and don''t need all of their extended functionality... and active scaffold doesn''t play well with rails 2.1.0... thanks, - FJM --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matt Darby
2008-Jul-01 01:44 UTC
Re: tweaking this to get a get a hash of namespaced models
> what i want is some kind of way to have all my models and their > associated namespaces in some kinda hash or array or something that i > can use to refer to them in an administrationy menu...Don''t know about the namespaces bit, but this will get a list of all your models: http://blog.matt-darby.com/2008/05/16/iterating-over-all-models-in-rails/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frankjmattia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-01 01:51 UTC
Re: tweaking this to get a get a hash of namespaced models
yeah saw that but as far as i can tell, it only works if those models are loaded... ive tried it and didnt get much success.. thanks tho. On Jun 30, 9:44 pm, Matt Darby <m...-0eUD8CxtpZOb3c84sXp8cg@public.gmane.org> wrote:> > what i want is some kind of way to have all my models and their > > > associated namespaces in some kinda hash or array or something that i > > can use to refer to them in an administrationy menu... > > Don''t know about the namespaces bit, but this will get a list of all > your models: > > http://blog.matt-darby.com/2008/05/16/iterating-over-all-models-in-ra...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
\"Wolas!\"
2008-Jul-01 12:15 UTC
Re: tweaking this to get a get a hash of namespaced models
class ListFiles def initialize path @dirs = [] @files = [] @platform = "/" @platform = "\\" if PLATFORM =~ /win/ @root_path = os_path path root = Dir.open(@root_path) scan root end def list_files recurse @files end def recurse while @dirs != [] path = @dirs.pop dir = Dir.open(path) scan dir end end def scan dir local_path = dir.path dir.each do |item| path = os_join local_path, item (File.directory?(path) ? @dirs.push(path) : @files.push(path)) unless item.find {|r| r=~/^\./ } end end def os_join *args args.join(@platform) end def os_path path if path.include?("\\") p = path.split("\\") elsif path.include?("/") p = path.split("/") end path = os_join p path end end you use it like: f = ListFiles.new(''./app/models/'') f.list_files and will return an array of files in that directory with paths. it will ignore .name files (svn git...) It is one of our home scripts, not very beautifull, but works. On Jul 1, 2:51 am, "frankjmat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <frankjmat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yeah saw that but as far as i can tell, it only works if those models > are loaded... > > ive tried it and didnt get much success.. thanks tho. > > On Jun 30, 9:44 pm, Matt Darby <m...-0eUD8CxtpZOb3c84sXp8cg@public.gmane.org> wrote: > > > > what i want is some kind of way to have all my models and their > > > > associated namespaces in some kinda hash or array or something that i > > > can use to refer to them in an administrationy menu... > > > Don''t know about the namespaces bit, but this will get a list of all > > your models: > > >http://blog.matt-darby.com/2008/05/16/iterating-over-all-models-in-ra...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---