Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to share a collection of model files across many apps?

Reply
Thread Tools

How to share a collection of model files across many apps?

 
 
Elliott Blatt
Guest
Posts: n/a
 
      03-23-2007
Hi,

I've got three files that (a.rb, b.rb, c.rb) that currently live in
app/models.
I'd like these models to shared by multiple rails apps. These models are
associated with a separate database.

My rails projects are contained in a directory that looks like this:

projects/

proj1/ proj2/ proj3/ common/


common/
a.rb b.rb c.rb


My idea is to do this:

In proj1/lib/, symlink to ../../common/

lib/
common/ (which is a symlink)


My question is:
How do I tell rails to load the files pointed to by the symlink named
'common' in the lib directory?


I've tried:

cofig/environment.rb

include 'lib/common'

Thanks for your input.
EB

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Phillip Gawlowski
Guest
Posts: n/a
 
      03-23-2007
Elliott Blatt wrote:
> Hi,
>
> I've got three files that (a.rb, b.rb, c.rb) that currently live in
> app/models.
> I'd like these models to shared by multiple rails apps. These models are
> associated with a separate database.
>
> My rails projects are contained in a directory that looks like this:
>
> projects/
>
> proj1/ proj2/ proj3/ common/
>
>
> common/
> a.rb b.rb c.rb
>
>
> My idea is to do this:
>
> In proj1/lib/, symlink to ../../common/
>
> lib/
> common/ (which is a symlink)
>
>
> My question is:
> How do I tell rails to load the files pointed to by the symlink named
> 'common' in the lib directory?


First, you might want to ask this at the Rails Mailinglist.

Secondly, your solution wouldn't be portable, as only Unixes (MacOS,
HP-UX, OpenSolaris, Linux) understand symlinks. Windows doesn't
understand POSIX symlinks at all.


--
Phillip "CynicalRyan" Gawlowski

Rule of Open-Source Programming #15:

If you like it, let the author know. If you hate it, let the author
know why.

 
Reply With Quote
 
 
 
 
RubyTalk@gmail.com
Guest
Posts: n/a
 
      03-23-2007
On 3/23/07, Elliott Blatt <(E-Mail Removed)> wrote:
> Hi,
>
> I've got three files that (a.rb, b.rb, c.rb) that currently live in
> app/models.
> I'd like these models to shared by multiple rails apps. These models are
> associated with a separate database.
>
> My rails projects are contained in a directory that looks like this:
>
> projects/
>
> proj1/ proj2/ proj3/ common/
>
>
> common/
> a.rb b.rb c.rb
>
>
> My idea is to do this:
>
> In proj1/lib/, symlink to ../../common/
>
> lib/
> common/ (which is a symlink)
>
>
> My question is:
> How do I tell rails to load the files pointed to by the symlink named
> 'common' in the lib directory?
>
>
> I've tried:
>
> cofig/environment.rb
>
> include 'lib/common'
>
> Thanks for your input.
> EB
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


If you are using svn:

svn externals works well for this. I would create a tag of the libs so
when you create tags of your projects you will not have to change the
external -r option.

http://svnbook.red-bean.com/en/1.0/ch07s03.html

There are unix programs that will keep directories synced.

Stephen Becker IV

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      03-23-2007
On Sat, Mar 24, 2007 at 12:24:27AM +0900, Elliott Blatt wrote:
> I've got three files that (a.rb, b.rb, c.rb) that currently live in
> app/models.
> I'd like these models to shared by multiple rails apps. These models are
> associated with a separate database.
>
> My rails projects are contained in a directory that looks like this:
>
> projects/
>
> proj1/ proj2/ proj3/ common/
>
>
> common/
> a.rb b.rb c.rb
>
>
> My idea is to do this:
>
> In proj1/lib/, symlink to ../../common/
>
> lib/
> common/ (which is a symlink)
>
>
> My question is:
> How do I tell rails to load the files pointed to by the symlink named
> 'common' in the lib directory?


I'm going to have to do something like this soon.

Personally I want to avoid symlinks, and I think what you want should be
possible simply by adding the appropriate directory to config.load_paths,
e.g.

config.load_paths << "#{RAILS_ROOT}/../common/app/models"

Now, if you enter "site:rubyonrails.com config.load_paths" into Google,
there are two hits, and the second one looks like a Wiki page which explains
exactly this. Unfortunately, when I follow it at the moment all I see is
"Application error (Rails)"

But the 'Cached' link on Google works.

Another idea. If the model is called common/app/models/foo.rb, then you can
create stub files {proj1,proj2,proj3}/app/models/foo.rb which just contain
a single line:

require "#{RAILS_ROOT}/../common/app/models/foo.rb"

or even something which does a sub() on __FILE__

Regards,

Brian.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Wireless Network - Setup - How? See/share Files, share printers, how? Wayne Wireless Networking 2 04-08-2006 04:34 PM
V1.1 compilation model in V2.0 - Loading of UserControls across VDirs Anders Borum ASP .Net 1 11-28-2005 11:08 PM



Advertisments