README.md in enum_ish-1.4.1 vs README.md in enum_ish-1.5.0
- old
+ new
@@ -24,11 +24,11 @@
Extend your class using EnumIsh and define an enum-like field:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status # status is a string field
enum_ish :status, ['enable', 'disable'] # status has 'enable' or 'disable'
end
```
@@ -80,11 +80,11 @@
Set default value:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status
enum_ish :status, ['enable', 'disable'], default: 'enable'
end
user = User.new
@@ -93,11 +93,11 @@
Use default value with block:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status, :flag
enum_ish :status, ['enable', 'disable'], default: -> { flag ? 'enable' : 'disable' }
end
user = User.new
@@ -108,11 +108,11 @@
Generate predicate methods:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status
enum_ish :status, ['enable', 'disable'], predicate: true
end
user = User.new
@@ -123,11 +123,11 @@
Without prefix:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status
enum_ish :status, ['enable', 'disable'], predicate: { prefix: false }
end
user = User.new
@@ -140,11 +140,11 @@
Generate getter and setter for aliased symbols instead of raw values:
```ruby
class User
- extend EnumIsh
+ include EnumIsh::Base
attr_accessor :status
enum_ish :status, { _enable: 'enable', _disable: 'disable' }, accessor: true
end
user = User.new
@@ -159,11 +159,11 @@
Generate accessor:
```ruby
class User < ActiveRecord::Base
- extend EnumIsh
+ include EnumIsh::Base
enum_ish :status, { _enable: 'enable', _disable: 'disable' }, accessor: true
end
User.where(status: :_enable) #=> SELECT "users".* FROM "users" WHERE "users"."status" = "enable"
```
@@ -172,11 +172,11 @@
Generate scope:
```ruby
class User < ActiveRecord::Base
- extend EnumIsh
+ include EnumIsh::Base
enum_ish :status, ['enable', 'disable'], scope: true
end
User.with_status(:enable) #=> SELECT "users".* FROM "users" WHERE "users"."status" = "enable"
User.with_status_not(:enable) #=> SELECT "users".* FROM "users" WHERE "users"."status" != 'enable'
@@ -186,17 +186,28 @@
Generate validation:
```ruby
class User < ActiveRecord::Base
- extend EnumIsh
+ include EnumIsh::Base
enum_ish :status, ['enable', 'disable'], validate: true
end
user = User.new
user.status = 'INVALID'
user.valid? #=> false
```
+
+### Dictionary cache
+
+You can enable dictionary cache using rack middleware:
+
+```ruby
+Rails.application.config.middleware.use EnumIsh::DictionaryCache
+```
+
+This middleware enables dictionary cache for each request.
+Prformance of dictionary lookup will be improved in case one dictionary is used repeatedly in the same request.
## Contributing
Bug reports and pull requests are welcome at https://github.com/kanety/enum_ish.