Class: Ruse::TypeResolver
- Inherits:
-
Object
- Object
- Ruse::TypeResolver
- Defined in:
- lib/ruse/injector.rb
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.
75 76 77 |
# File 'lib/ruse/injector.rb', line 75 def initialize(injector) @injector = injector end |
Class Method Details
.classify(term) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/ruse/injector.rb', line 89 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
84 85 86 87 |
# File 'lib/ruse/injector.rb', line 84 def build(identifier) type = resolve_type identifier object_factory.build(type) end |
#can_build?(identifier) ⇒ Boolean
79 80 81 82 |
# File 'lib/ruse/injector.rb', line 79 def can_build?(identifier) type_name = self.class.classify(identifier) load_type type_name end |