Last active
August 29, 2015 13:56
-
-
Save fgarcia/9277156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'virtus' | |
# This Works! | |
class User | |
include Virtus.model | |
attribute :name, String | |
attribute :group, String | |
end | |
# Class User trying to make private attributes | |
class User_Private | |
include Virtus.model | |
attribute :name, String, :accessor => private | |
attribute :group, String, :accessor => private | |
end | |
# This fails! | |
u = User_Private.new(name:"demo", group:"staff") | |
### | |
# I am trying to have this ... | |
### | |
class UserForm < User | |
# ... something to make all attributes READ-ONLY | |
end | |
u = UserForm.new(name:"demo", group:"staff") | |
u = UserForm.new(user_post_data_hash) | |
u.name = 'other' # FAIL | |
u.name # OK | |
class UserEntity < User | |
# ... something to make all attributes PRIVATE | |
end | |
model = UserForm.new(name:"demo", group:"staff") | |
u = UserEntity(model) | |
u.name = 'other' # FAIL | |
u.name # FAIL | |
class UserValidationGUI < User | |
end | |
class UserValidationDomain < User | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My problem is that I try to avoid the standard Virtus object examples. Usually I split them in two groups. One case is for value-like containers (all attributes read-only) like UserForm. The other case is for state-containing objects. A class containing state, must expose no attributes, not even read-only.