Skip to content

Instantly share code, notes, and snippets.

@xymbol
Created October 29, 2013 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xymbol/7217672 to your computer and use it in GitHub Desktop.
Save xymbol/7217672 to your computer and use it in GitHub Desktop.
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
@juanazam
Copy link

Que increible como evoluciono esto en un dia jaja

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment