lib/twilio-ruby/rest/utils.rb in twilio-ruby-3.13.0 vs lib/twilio-ruby/rest/utils.rb in twilio-ruby-3.13.1

- old
+ new

@@ -26,8 +26,26 @@ something = something.gsub(/[A-Z][a-z]*/) { |s| "_#{s.downcase}" } something.gsub(/^_/, '') end end + protected + + def resource(*resources) + custom_resource_names = { sms: 'SMS', sip: 'SIP' } + resources.each do |r| + resource = twilify r + relative_path = custom_resource_names.fetch(r, resource) + path = "#{@path}/#{relative_path}" + enclosing_module = if @submodule == nil + Twilio::REST + else + Twilio::REST.const_get(@submodule) + end + resource_class = enclosing_module.const_get resource + instance_variable_set("@#{r}", resource_class.new(path, @client)) + end + self.class.instance_eval { attr_reader *resources } + end end end end