https://github.com/avinashbot/lazy_lazer
create custom lightweight lazily loaded data models using a simple dsl
https://github.com/avinashbot/lazy_lazer
lazy-loading model ruby
Last synced: 16 days ago
JSON representation
create custom lightweight lazily loaded data models using a simple dsl
- Host: GitHub
- URL: https://github.com/avinashbot/lazy_lazer
- Owner: avinashbot
- License: mit
- Created: 2017-08-03T19:50:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-03T15:42:02.000Z (over 7 years ago)
- Last Synced: 2025-04-19T11:08:39.262Z (about 1 month ago)
- Topics: lazy-loading, model, ruby
- Language: Ruby
- Homepage:
- Size: 127 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
![]()
```ruby
require 'lazy_lazer'class User
include LazyLazerproperty :name, :required
property :email, default: '[email protected]'
property :created_at, from: :creation_time_utc, with: ->(t) { Time.at(t) }
property :age, with: :to_i
property :twitter_handle, :nil
property :favorite_ice_creamdef say_flavor!
if exists_locally?(:favorite_ice_cream)
puts "#{name} currently likes #{favorite_ice_cream}."
else
puts "#{name} doesn't have a favorite ice cream flavor yet."
end
enddef try_another_flavor!
delete_attribute(:favorite_ice_cream)
not_fully_loaded!
puts "#{name} just tried #{favorite_ice_cream}. They love it!"
endprivate
def lazer_reload
fully_loaded! # mark model as fully updated
{ favorite_ice_cream: %w[vanilla strawberry chocolate].sample }
end
enduser = User.new(name: 'Blinky', creation_time_utc: 1500000000, age: '21')
user.name #=> "Blinky"
user.email #=> "[email protected]"
user.created_at #=> 2017-07-14 03:40:00 +0100
user.age #=> 21
user.twitter_handle #=> niluser.favorite_ice_cream #=> "chocolate"
user.favorite_ice_cream #=> "chocolate"
user.reload.favorite_ice_cream #=> "vanilla"user.say_flavor! #=> Blinky currently likes vanilla.
user.try_another_flavor! #=> Blinky just tried strawberry. They love it!
```
documentation -
contributing -
mit licensed
created for redd -
logo font is zaguatica