Which source file?

Windows development environment.

After starting webrick using
ruby script/server webrick --debugger

I started poking around and found …


(rdb:2) @devise_mapping
#<Devise::Mapping:0x7182728 @for=[:authenticatable, :activatable,
:confirmable,
:recoverable, :rememberable, :timeoutable, :trackable, :validatable],
@klass=“Us
er”, @route_options={}, @path_names={:confirmation=>“confirmation”,
:password=>"
password", :sign_in=>“sign_in”, :sign_out=>“sign_out”},
@path_prefix="/", @name=
:user, @as=:users>
(rdb:2) @devise_mapping.class
Devise::Mapping


Is there a convenient way to find out which source module
defined/defines the class Devise::Mapping ?

Ralph S. wrote:

Windows development environment.

How is that relevant?

After starting webrick using
ruby script/server webrick --debugger

I started poking around and found …


(rdb:2) @devise_mapping
#<Devise::Mapping:0x7182728 @for=[:authenticatable, :activatable,
:confirmable,
:recoverable, :rememberable, :timeoutable, :trackable, :validatable],
@klass=“Us
er”, @route_options={}, @path_names={:confirmation=>“confirmation”,
:password=>"
password", :sign_in=>“sign_in”, :sign_out=>“sign_out”},
@path_prefix=“/”, @name=
:user, @as=:users>
(rdb:2) @devise_mapping.class
Devise::Mapping


Is there a convenient way to find out which source module

What’s a source module?

defined/defines the class Devise::Mapping ?

Yes. Use grep. Or look in the rdoc.

And remember that it might be defined in more than one place, since
modules and classes can be reopened.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

i know only Device::Mapping, maybe there is someone misspell it.

Liu Lantao wrote:

i know only Device::Mapping, maybe there is someone misspell it.

“devise” is a gem for doing user authentication that I am beginning to
really like.

“devise” sits on top of the Warden rack middleware to accomplish user
authentication.

Marnen Laibow-Koser wrote:

Ralph S. wrote:

Windows development environment.

How is that relevant?

I don’t know! How files are handled might be different on different
development platforms.

Is there a convenient way to find out which source module

What’s a source module?

A file with source code in it, Marnen.

Ask a silly question …

The word “module” … like “include” … varies in meaning depending on
context.

defined/defines the class Devise::Mapping ?

Yes. Use grep. Or look in the rdoc.

And remember that it might be defined in more than one place, since
modules and classes can be reopened.

If, in a debugger, I enter the name of a block, the source file (er,
module) and line number is displayed. I like that. It’s very useful.

I was hoping that there might have been a way (perhaps an array of names
and line numbers of source files?), that Ruby/Rails would keep track of
all the places that a class had been constructed from?

Ralph S. wrote:

Marnen Laibow-Koser wrote:

Ralph S. wrote:

Windows development environment.

How is that relevant?

I don’t know! How files are handled might be different on different
development platforms.

I suppose. But in this case, no. So far as I know, there’s no
significant difference in Ruby source code handling between OSes, except
perhaps for case-sensitivity issues. (That said, I don’t use Windows,
so it’s conceivably that I’m not aware of something.)

Is there a convenient way to find out which source module

What’s a source module?

A file with source code in it, Marnen.

The term “module” is never used in that sense by Ruby developers.

Ask a silly question …

The word “module” … like “include” … varies in meaning depending on
context.

“Module” has exactly one meaning in a Ruby context, and that wasn’t it.
:slight_smile: If you mean “file”, then say it.

defined/defines the class Devise::Mapping ?

Yes. Use grep. Or look in the rdoc.

And remember that it might be defined in more than one place, since
modules and classes can be reopened.

If, in a debugger, I enter the name of a block, the source file (er,
module)

Er, file.

and line number is displayed. I like that. It’s very useful.

Yup. The reason I didn’t originally suggest the debugger is that I was
trying to come up with a suggestion that didn’t require knowing where to
put a breakpoint.

I was hoping that there might have been a way (perhaps an array of names
and line numbers of source files?), that Ruby/Rails would keep track of
all the places that a class had been constructed from?

I doubt it, but I’m not enough of a Ruby internals geek to say for sure.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Ralph S. wrote:

Windows development environment.

How is that relevant?

I don’t know! How files are handled might be different on different
development platforms.

I suppose. But in this case, no. So far as I know, there’s no
significant difference in Ruby source code handling between OSes, except
perhaps for case-sensitivity issues. (That said, I don’t use Windows,
so it’s conceivably that I’m not aware of something.)

Ruby (Rails?) does so much that is different depending on case.

Windows stores file names with case sensitivity but accesses the files
without regard to filename case.

Right. The filesystem is case-preserving but not case-sensitive.

Thus the Filenames “SomeFile” and “Somefile” are different strings, they
refer to the same underlying file in Windows.

But if Rails cares about filename case sensitivity …

Rails’ autoloading routines expect snake-case filenames, so MyModel will
be loaded from my_model.rb.

Now, on Windows, if there’s a file My_Model.rb, then the filesystem will
return that when my_model.rb is requested, whereas most *nix filesystems
will not.

But that’s up to the filesystem. AFAIK Ruby simply requests a particular
file, and doesn’t know anything about how the filesystem will satisfy
that request.

So … does Rails care about case sensitivity in filenames?

Sort of, as outlined above.

I have found it to be best to always act as if the filesystem is
case-sensitive, even if it isn’t.

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Devise::Mapping


Is there a convenient way to find out which source module
defined/defines the class Devise::Mapping ?

If you’re on 1.9, you can use Method#source_location to see where it’s
source was defined (at least).

This tool leverages that:
ri_for gem

C:> gem install ri_for
C:…>script\server

drops into a debugger

(rdb:1) require ‘ri_for’
(rdb:2) Devise::Mapping.ri_for :some_method
(rdb:2) Devise::Mapping.desc

GL.
-r

Windows development environment.

How is that relevant?

I don’t know! How files are handled might be different on different
development platforms.

I suppose. But in this case, no. So far as I know, there’s no
significant difference in Ruby source code handling between OSes, except
perhaps for case-sensitivity issues. (That said, I don’t use Windows,
so it’s conceivably that I’m not aware of something.)

Ruby (Rails?) does so much that is different depending on case.

Windows stores file names with case sensitivity but accesses the files
without regard to filename case.

Thus the Filenames “SomeFile” and “Somefile” are different strings, they
refer to the same underlying file in Windows.

But if Rails cares about filename case sensitivity …

So … does Rails care about case sensitivity in filenames?