# Reimplementation address book program

**URL:** <https://www.ruby-forum.com/t/reimplementation-address-book-program/156784>\
**Category:** Ruby\
**Created:** [January 2, 2009, 9:02pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784 "2009-01-02T21:02:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 2, 2009, 9:02pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/1 "2009-01-02T21:02:45Z")

</div>

On one of my servers (linux) I have a nice address book over ldap.  
It is automatically integrated with thunderbird and other programs,  
but none of them is capable of modifying (or at least easily).

Since I want it very simple and error prone I did it myself, but in  
PHP.

It works pretty fine but every time I look to the code I get disgusted  
and I haven’t still added some necessary features, so given that I  
want to rewrite it in ruby, I need some hints…

I may use rails in the future but I want to start very smoothly, it  
was implemented in php + smarty, and that’s fine like approach.

I only need 2 things:

- insert a new record
- modify a record from a list  
Sorting searching etc are not really necessary, and integrity checks  
should be done with javascript (as it is now).

I want to do it as smart and possible, because mainly I want to learn  
and not less important I want to maintain code that I like…  
THanks for any hints

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 2, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/2 "2009-01-02T21:03:21Z")

</div>

I started to do some searches and I find out I can use net/ldap for  
manipulating data and amrita2 to create the templates.  
What do you think??

Another thing, what does :: really mean??  
Net::LDAP means what? Look in the Net module for the LDAP class??

And why sometimes i find (fake example)  
String.join, String#join, Net::LDAP

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 2, 2009, 9:04pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/3 "2009-01-02T21:04:32Z")

</div>

Looks like amrita is dead or almost, I find almost no documentation  
other than the source code and a readme file.

Should I really go for rails? Otherwise what else??  
I only need to generate smartly some forms and get the output of them.  
Rails is not directly usable because my “db” is an ldap tree…

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 3, 2009, 8:56am UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/4 "2009-01-03T08:56:08Z")

</div>

On 2 Gen, 20:12, andrea [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Looks like amrita is dead or almost, I find almost no documentation  
> other than the source code and a readme file.
> 
> Should I really go for rails? Otherwise what else??  
> I only need to generate smartly some forms and get the output of them.  
> Rails is not directly usable because my “db” is an ldap tree…

Is there anybody out there??  
I went to haml finally, which looks really nice. It’s even too much  
powerful, it tempts me to write everything in one page 😉

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 3, 2009, 12:32pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/5 "2009-01-03T12:32:03Z")

</div>

On Sat, Jan 3, 2009 at 7:54 AM, andrea [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there anybody out there??

It might help if you actually posed a question, or phrased your problem  
better. I _think_ you are trying to make a web based administration  
interface  
to an LDAP directory, but I am not sure.

You might get better information on Rails talk, but your core problem is  
your  
backend - its an LDAP directory not a database, so your problem might be  
better served by anything that uses DataMapper, which doesn’t restrict  
your  
data sources.

Merb might be a better choice, or possibly even Sinatra, which is  
simpler and  
might put less barriers in your learning (and works very well with Haml,  
which  
you like).

regards,  
Richard.

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 4, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/6 "2009-01-04T20:55:32Z")

</div>

On 3 Gen, 12:30, Richard C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> data sources.
> 
> Merb might be a better choice, or possibly even Sinatra, which is simpler and  
> might put less barriers in your learning (and works very well with Haml, which  
> you like).
> 
> regards,  
> Richard.

Actually there were a few question marks and I thought I explained the  
problem, but I’ll try again…

I need a frontend for the users which enables to modify / add and  
pretty view entries from an ldap tree.  
I just wanted some hints about what to use / how should I design it.  
Couldn’t I just use mod\_ruby instead of any kind of framework?  
I need a framework to interpret the haml code maybe? Or I could use  
the Haml::Engine?

This is a first attempt of class structure:

class Entry  
@@multiple = [“mobile”, “telephoneNumber”, “mail”]  
@@long = [“description”]

end

class Person \< Entry  
@@attrs = {  
:attributes =\> [“cn”, “sn”, “o”, “ou”, “mobile”,  
“telephoneNumber”, “mail”, “description”],  
:strict =\> [“cn”, “sn”],  
:dn =\> [“dn”]  
}  
def initialize(cn, sn)

end

end

class Factory \< Entry  
@@attrs = {  
:attributes =\>  
[“o”,“telephoneNumber”,“facsimileTelephoneNumber”,“l”,“postalCode”,“street”,“description”],  
:strict =\> [“o”],  
:dn =\> [“o”]  
}  
def initialize(org)

end  
end

Depending on what you’re loooking you get different attributes, it is  
fine to do this check directly in the haml template?

They will be just input boxes or text areas with some strings already  
in or empty, it’s not so difficult…

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 4, 2009, 10:10pm UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/7 "2009-01-04T22:10:19Z")

</div>

On Sun, Jan 4, 2009 at 1:53 PM, andrea [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Actually there were a few question marks and I thought I explained the  
> problem, but I’ll try again…
> 
> I need a frontend for the users which enables to modify / add and  
> pretty view entries from an ldap tree.  
> I just wanted some hints about what to use / how should I design it.

These are hard questions to answer, because they involve many other  
questions (like, do you require a certain look or user interface, are  
you adverse to learning a new framework, time constraints,  
performance, etc.) Rails is pretty heavy duty, but if you plan on  
learning it anyway and don’t mind a little feature bloat, I suppose it  
might work for you.

> Couldn’t I just use mod\_ruby instead of any kind of framework?  
> I need a framework to interpret the haml code maybe? Or I could use  
> the Haml::Engine?

Are you stuck with Haml? Maybe take a look at Camping and Markaby if  
the requirements for the web-based app are not overly rigorous.

I haven’t played with the LDAP library yet, so I can’t comment on it.

Good luck!

Todd

---

<div class="post-metadata">

**Author:** ![andrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@andrea](https://www.ruby-forum.com/u/andrea)\
**Post date:** [January 5, 2009, 11:15am UTC](https://www.ruby-forum.com/t/reimplementation-address-book-program/156784/8 "2009-01-05T11:15:40Z")

</div>

On 4 Gen, 22:08, Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sun, Jan 4, 2009 at 1:53 PM, andrea [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> These are hard questions to answer, because they involve many other  
> questions (like, do you require a certain look or user interface, are  
> you adverse to learning a new framework, time constraints,  
> performance, etc.) Rails is pretty heavy duty, but if you plan on  
> learning it anyway and don’t mind a little feature bloat, I suppose it  
> might work for you.

So I think I will go to rails after, but I like to do things gradually  
when I’m learning something.  
I’m not in hurry (there’s already an interfacean working even if  
incomplete)  
d I’m firstly interested in learning now.

> Are you stuck with Haml? Maybe take a look at Camping and Markaby if  
> the requirements for the web-based app are not overly rigorous.

No Haml is really fine, it was just to know if it could work anyway…  
I think  
it could, as long as apache calls a ruby file each time and the ruby  
file  
renders the template

> I haven’t played with the LDAP library yet, so I can’t comment on it.

There’s active\_ldap but I don’t get it to work on Leopard and even on  
ubuntu 8.04, not a big deal net/ldap is just fine for me.

I don’t understand why only here on ruby half of my messages are not  
actually  
posted even it gives me no errros…  
I’ll have to remember to write them inside textmate so I can repost  
them.

This is a start point of the classes I need (not many in fact)

class Entry  
attr\_reader :multiple, :long  
def initialize(ar1, ar2)  
@multiple = [“mobile”, “telephoneNumber”, “mail”]  
@long = [“description”]  
end  
end

class Person \< Entry

# they can just be readonly attributes

attr\_reader :attrs, :cn, :sn, :fields

# inside other there is a hash containing all other fields set

def initialize(cn, sn, other)  
@attrs = {  
:attributes =\> [“cn”, “sn”, “o”, “ou”, “mobile”,  
“telephoneNumber”, “mail”, “description”],  
:strict =\> [“cn”, “sn”],  
:dn =\> [“dn”]  
}  
# super  
@fields = {:cn =\> cn, :sn =\> sn}  
other.each\_pair do |key, val|  
# don’t overwrite already compiled fields  
if @attrs[:attributes].member?(key) and (not @fields.has\_key?  
(key))  
@fields[key] = val  
end  
end  
end

def to\_s  
pp @fields  
end  
end

class Factory \< Entry  
attr\_reader :attrs  
def initialize(o)  
@@attrs = {  
:attributes =\>  
[“o”,“telephoneNumber”,“facsimileTelephoneNumber”,“l”,“postalCode”,“street”,“description”],  
:strict =\> [“o”],  
:dn =\> [“o”]  
}  
@o = o  
end  
end

Then there are some methods that retrieve or updates the informations  
and  
some templates to show everything.
