-
Notifications
You must be signed in to change notification settings - Fork 1
Entities
The basics are the following:
Suppose we have a User entity with a field name.
u = User.new
creates a new user.
u.name
gets the name attribute.
u.put("name", "Alice")
sets the name attribute to “Alice”.
u.name = "Alice"
does the same as above as long as you have the following line in your User model:
include PIQLEntity
u.save
saves the user to the database.
There is also an alternate constructor that takes in a hash that maps attribute names to values. This makes it possible to do the following in the create
controller method:
User.new(params[:user])
.
In this case the passed in hash would like something like {"name" => "Bob", "password" => "12345"}
.
- The models directory of your Rails app should have files that are the lowercased name of each Entity that you want to add functionality to.
- This file should include a class definition with a name matching the Entity. The class should not inherit from anything.
- The class should mix-in (ie.
include
)PIQLEntity
For example, the Entity user would have a file app/models/user.rb
that looks like the following:
class User
include PIQLEntity
# Other code
end