Created
October 29, 2013 16:11
-
-
Save xymbol/7217672 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
module ActiveModel | |
class RootSetting | |
attr_reader :klass, :value | |
def initialize(klass, value) | |
@klass = klass | |
@value = value | |
end | |
def root | |
from_class || from_serializer || from_value | |
end | |
private | |
def from_class | |
klass.root_name if set? || default? && set_or_default_in_class? | |
end | |
def from_serializer | |
klass._root if default? | |
end | |
alias_method :from_value, :value | |
def set? | |
value == true | |
end | |
def set_or_default_in_class? | |
klass._root == true || klass._root.nil? | |
end | |
def default? | |
value.nil? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Que increible como evoluciono esto en un dia jaja