Adding custom code

View as Markdown

This page covers how to add custom logic, methods, and dependencies to your Ruby SDK.

Adding custom logic

To get started adding custom code:

1

Create a new file and add your custom logic

lib/<gem_name>/helper.rb
1module YourGem
2 class Helper
3 def self.my_helper
4 puts "Hello World!"
5 end
6 end
7end
2

Add your file to .fernignore

.fernignore
1# Specify files that shouldn't be modified by Fern
2
3lib/<gem_name>/helper.rb
3

Consume the helper

Now your users can consume the helper function by importing it from the SDK.

1require "your_gem"
2
3YourGem::Helper.my_helper

Adding custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g. client.my_method() ) by inheriting the Fern generated client and then extending it.

1

Update generators.yml configuration

Name your Fern-generated client something like BaseClient to reflect that this client will be extended.

generators.yml
1- name: fernapi/fern-ruby-sdk
2 version: 1.0.0-rc69
3 config:
4 clientClassName: BaseClient
2

Import and extend the generated client

First, import the Fern generated base client and extend it. Then, add whatever methods you want.

lib/<gem_name>/my_client.rb
1require_relative "client"
2
3module YourGem
4 class MyClient < BaseClient
5 def my_helper
6 puts "Hello World!"
7 end
8 end
9end
3

Update .fernignore

Add the my_client.rb to .fernignore.

.fernignore
1+ lib/<gem_name>/my_client.rb
4

Consume the method

Instead of constructing the generated client, your users will want to construct the extended client.

1require "your_gem"
2
3client = YourGem::MyClient.new

Now your users can consume the helper function by importing it from the SDK.

1client.my_helper

Adding custom dependencies

Pro and Enterprise feature

This feature is available only for the Pro and Enterprise plans. To get started, reach out to support@buildwithfern.com.

To add gems that your custom code requires, update your generators.yml.

generators.yml
1- name: fernapi/fern-ruby-sdk
2 version: 1.0.0-rc69
3 config:
4 extraDependencies:
5 faraday: ">= 1.0"
6 extraDevDependencies:
7 rspec: "~> 3.0"