Class: Smith::ACL::Factory

Inherits:
Object
  • Object
show all
Extended by:
Utils
Includes:
Logger
Defined in:
lib/smith/messaging/factory.rb

Class Method Summary collapse

Methods included from Utils

agent_directories, check_and_create_directory, class_from_name, class_name_from_path, path_from_class, split_path

Methods included from Logger

included

Class Method Details

.create(type, content = nil, &blk) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smith/messaging/factory.rb', line 11

def create(type, content=nil, &blk)
  if type.respond_to?(:serialize_to_string)
    return type
  else
    clazz = (type.is_a?(::Protobuf::Message)) ? type : class_from_name(type)

    if blk
      clazz.new.tap { |m| blk.call(m) }
    else
      (content.nil?) ? clazz.new : clazz.new(content)
    end
  end
end