module Partializer::Resolver
Public Instance Methods
create_partializer(name)
click to toggle source
# File lib/partializer/resolver.rb, line 3 def create_partializer name context = self.kind_of?(Class) ? self : self.class clazz = "#{context.name}::#{name.to_s.camelize}".constantize clazz.new end
resolve(arg)
click to toggle source
# File lib/partializer/resolver.rb, line 9 def resolve arg case arg when Hash resolve_hash(arg) when String, Symbol resolve_sym(arg) when Partializer::Collection arg else raise ArgumentError, "Could not partialize: #{arg}" end end
resolve_hash(hash)
click to toggle source
# File lib/partializer/resolver.rb, line 22 def resolve_hash hash Partializer::Collection.new 'hash', hash.keys, hash end
resolve_partializer(arg)
click to toggle source
# File lib/partializer/resolver.rb, line 46 def resolve_partializer arg arg.sub!(/^_/, '') instance = create_partializer(arg) {instance.class.name.to_s.demodulize.underscore => instance.partials} end
resolve_sym(arg)
click to toggle source
Creates a Collection
from a Symbol :gallery gallery -> :gallery partials: [:gallery]
# File lib/partializer/resolver.rb, line 30 def resolve_sym arg value = resolve_value arg arg = arg.to_s.sub(/^_/, '') if value.to_s == arg.to_s Partializer::Collection.new 'sym', arg else Partializer::Collection.new 'sym', arg, {arg.to_sym => value} end end
resolve_value(arg)
click to toggle source
a Partializer
or a sym!
# File lib/partializer/resolver.rb, line 41 def resolve_value arg arg = arg.to_s arg[0] == '_' ? resolve_partializer(arg) : arg.to_sym end