When I was implementing our home-grown authorization system, I have to know what controllers are available, for the given controller, what actions are available. This shouldn't difficult using reflection within Ruby. But after reading the source code of Merb, I found it is dead simple to get what you want:
- Application.subclasses_list
- YourController.callable_actions
Here is the code in my Role modle:
Apr 10, 2009
Apr 4, 2009
Daycare
April 1 was the first day of my baby girl in a daycare center. Since that daycare center is supposed to be the best in town, I've been on the waiting list for really a long time, even before she was born. I was expecting some difficulties, both physical and emotional, but I've never thought it was that hard.
The beginning in the morning wasn't that pleasure. For the first time I know my baby girl is that loud, she cried really hard and not letting her mom go. We sneaked into the private room, which has a one-way window on the wall, so we can watch her, even can listen to her with the help of headphone. No teacher can calm her down. So the mom had to get into the classroom...
Then the next day, she seems to be OK in the morning, but just before the end of the day, the teacher called, my baby girl caught a fever - 101.3F. Then in the next two days we have to fight with the fever. Today, I even had to bring her to ER...
She is totally fine now. As the first time parents, my wife and I really enjoy this whole new experience. We've learned a lot, and we are continuing the process, it is like perusing another Ph. D again, only the experience is much better.
Here is what we learned from the daycare:
1. Your kid will like there, the daycare is like a Toys R Us opened in a small school.
2. Your kid will grow strong, the daycare is like a germ camp.
The beginning in the morning wasn't that pleasure. For the first time I know my baby girl is that loud, she cried really hard and not letting her mom go. We sneaked into the private room, which has a one-way window on the wall, so we can watch her, even can listen to her with the help of headphone. No teacher can calm her down. So the mom had to get into the classroom...
Then the next day, she seems to be OK in the morning, but just before the end of the day, the teacher called, my baby girl caught a fever - 101.3F. Then in the next two days we have to fight with the fever. Today, I even had to bring her to ER...
She is totally fine now. As the first time parents, my wife and I really enjoy this whole new experience. We've learned a lot, and we are continuing the process, it is like perusing another Ph. D again, only the experience is much better.
Here is what we learned from the daycare:
1. Your kid will like there, the daycare is like a Toys R Us opened in a small school.
2. Your kid will grow strong, the daycare is like a germ camp.
Mar 28, 2009
Constanize the merb controller
I am implementing an authorization system now. There are two sub-system:
1. Role based control system
2. Rule based authorization system
The role sub-system is relatively easy to implement. I am going to talk about the rule based authorization system only here.
According to the requirement, the authorization system is very detail orientated. What does that mean? I can give you a very simple example here:
For role 1, he can view e1, but can view, edit, delete e2
For role 2, he can view, edit, but not delete e1, can view e3
For role 3, he can view, edit and delete, archive e1, no any permissions on e2 and e3
In our system, we have 50+ entities, and maybe 20 roles. You can imagine how many possibilities you can have here. Thank god, I've designed the system mostly in the RESTful way. So the next problem is how can I get all the controllers and callable actions. There are two situations I have to address first:
1. My controllers has name space
Purchasing::PurchaseOrder
2. My controllers not inherited from the Application directly, they might have their own hierarchy.
It turns out pretty simple in Merb and Ruby way.(This is another reason I like it over Java's reflection). The key is to Dynamically instaniating a class by name. Here is the code.
1. Role based control system
2. Rule based authorization system
The role sub-system is relatively easy to implement. I am going to talk about the rule based authorization system only here.
According to the requirement, the authorization system is very detail orientated. What does that mean? I can give you a very simple example here:
For role 1, he can view e1, but can view, edit, delete e2
For role 2, he can view, edit, but not delete e1, can view e3
For role 3, he can view, edit and delete, archive e1, no any permissions on e2 and e3
In our system, we have 50+ entities, and maybe 20 roles. You can imagine how many possibilities you can have here. Thank god, I've designed the system mostly in the RESTful way. So the next problem is how can I get all the controllers and callable actions. There are two situations I have to address first:
1. My controllers has name space
Purchasing::PurchaseOrder
2. My controllers not inherited from the Application directly, they might have their own hierarchy.
It turns out pretty simple in Merb and Ruby way.(This is another reason I like it over Java's reflection). The key is to Dynamically instaniating a class by name. Here is the code.
Mar 21, 2009
DataMapper - some tiny issues within 0.9.9
I am working on a home-grown authorization system. It is very customized for our special requirement. I have to hack DataMapper to get the job done. The more I dig in DM, the more I love it. I can't imagine how much code I have to write to do the same thing if I do it with Java. As a relative new ORM framework, it sure has some corners that might not work well for you, following are some thing I found out in one day:
1. auto_migrate! vs. auto_upgrade!
1. auto_migrate! vs. auto_upgrade!