Class: ShareWith::ServiceDataFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/share_with/service_data.rb

Overview

Convert an argument to a ServiceDataType object.

Class Method Summary collapse

Class Method Details

.create(args) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/share_with/service_data.rb', line 166

def self.create(args)
  if args.instance_of? String
    res = ServiceDataType::Reference.new(args)
  else
    type = args[:type].to_s.split("_").map(&:capitalize).join
    raise InvalidDataType, type unless ShareWith::ServiceDataType.constants.include? type.to_sym

    res = Object.const_get("ShareWith::ServiceDataType::#{type}").new(args)
  end

  res
end