Class: Ruse::TypeResolver
- Inherits:
-
Object
- Object
- Ruse::TypeResolver
- Defined in:
- lib/ruse/activesupport.rb,
lib/ruse/type_resolver.rb
Overview
Eventually, the resolvers may be pluggable, in which case we could replace the normal TypeResolver with one specific to ActiveSupport. For now, we’ll just monkeypatch.
Class Method Summary collapse
Instance Method Summary collapse
- #build(identifier) ⇒ Object
- #can_build?(identifier) ⇒ Boolean
-
#initialize(injector) ⇒ TypeResolver
constructor
A new instance of TypeResolver.
Constructor Details
#initialize(injector) ⇒ TypeResolver
Returns a new instance of TypeResolver.
3 4 5 |
# File 'lib/ruse/type_resolver.rb', line 3 def initialize(injector) @injector = injector end |
Class Method Details
.classify(term) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ruse/type_resolver.rb', line 17 def self.classify(term) # lifted from active_support gem: lib/active_support/inflector/methods.rb string = term.to_s string = string.sub(/^[a-z\d]*/) { $&.capitalize } string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{ $2.capitalize}" }.gsub('/', '::') end |
Instance Method Details
#build(identifier) ⇒ Object
12 13 14 15 |
# File 'lib/ruse/type_resolver.rb', line 12 def build(identifier) type = resolve_type identifier object_factory.build(type) end |
#can_build?(identifier) ⇒ Boolean
7 8 9 10 |
# File 'lib/ruse/type_resolver.rb', line 7 def can_build?(identifier) type_name = self.class.classify(identifier) load_type type_name end |