Class: Smith::ACL::Factory
- Inherits:
-
Object
- Object
- Smith::ACL::Factory
- Includes:
- Logger
- Defined in:
- lib/smith/messaging/factory.rb
Class Method Summary collapse
Methods included from Logger
Class Method Details
.create(type, content = nil, &blk) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/smith/messaging/factory.rb', line 9 def create(type, content=nil, &blk) if type.respond_to?(:serialize_to_string) return type else clazz = (type.is_a?(::Protobuf::Message)) ? type : get_clazz(type) if blk clazz.new.tap { |m| blk.call(m) } else (content.nil?) ? clazz.new : clazz.new(content) end end end |
.get_clazz(type) ⇒ Object
23 24 25 |
# File 'lib/smith/messaging/factory.rb', line 23 def get_clazz(type) type.to_s.split(/::/).inject(Kernel) { |acc, t| acc.const_get(t) } end |