Skip to content

add computed fields

Choose a tag to compare

@fntz fntz released this 22 Feb 20:15
· 19 commits to master since this release
class MyModel extends Sirius.BaseModel
  @attrs: ["first_name", "last_name", "age"]
  @comp("full_name", "first_name", "last_name")
  @comp("age_and_full_name", "age", "full_name", (age, fn) -> "age: #{age}, #{fn}")  
  @validate :
    full_name:
      length: min: 4, max: 25

# then

model = new MyModel()
model.first_name("John")
model.last_name("Doe")
model.full_name() # => John Doe

model.age_and_full_name() # => null
model.age(21) 
model.age_and_full_name() # => age: 21, John Doe