README.md in virtus-0.3.0 vs README.md in virtus-0.4.0
- old
+ new
@@ -59,29 +59,33 @@
``` ruby
class Page
include Virtus
attribute :title, String
-
+
# default from a singleton value (integer in this case)
attribute :views, Integer, :default => 0
-
+
+ # default from a singleton value (boolean in this case)
+ attribute :published, Boolean, :default => false
+
# default from a callable object (proc in this case)
attribute :slug, String, :default => lambda { |page, attribute| page.title.downcase.gsub(' ', '-') }
-
+
# default from a method name as symbol
attribute :editor_title, String, :default => :default_editor_title
def default_editor_title
published? ? title : "UNPUBLISHED: #{title}"
end
end
-page = Page.new(:title => 'Virtus Is Awesome', :editor_title => 'Virtus README')
-page.slug # => 'virtus-is-awesome'
-page.views # => 0
-page.editor_title # => "UNPUBSLISHED: Virtus README"
+page = Page.new(:title => 'Virtus README')
+page.slug # => 'virtus-readme'
+page.views # => 0
+page.published # => false
+page.editor_title # => "UNPUBLISHED: Virtus README"
```
**Embedded Value**
``` ruby
@@ -236,10 +240,10 @@
**Custom Attributes**
``` ruby
require 'json'
-module MyAppClass
+module MyApp
# Defining the custom attribute(s)
module Attributes
class JSON < Virtus::Attribute::Object
primitive Hash