Skip to content

Add Dry Types gem and apply to Job.add#21

Merged
abreckner merged 3 commits intomasterfrom
dry-types-job
Apr 30, 2020
Merged

Add Dry Types gem and apply to Job.add#21
abreckner merged 3 commits intomasterfrom
dry-types-job

Conversation

@abreckner
Copy link
Contributor

We are adding the Dry Types gem to put some type checking onto the job hash used when adding a job.

This will help us surface type errors to the gem users when they are sending data over to the XPM Api for processing (which will in turn help with error checking and validation).

More info on Dry Types and hashes can be found here.

https://dry-rb.org/gems/dry-types/1.2/hash-schemas/

end

def add(access_token:, xero_tenant_id:, job:)
validated_job = XpmRuby::Schema::Job::Add[job]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder how we could drop all the :: operations? Maybe something like:

# lib/xpm_ruby/job.rb

require_relative "job/add_schema"

module XpmRuby
  module Job
    def add(...)
      validated_job = AddSchema[job]
    end
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I will have a think about it. I was following the structure from the client success gem. I think if we keep them in the same relative place in all our gems it might make it easier for our devs to work across gems.

But then again I am not 100% why the client success gem was structured this way.
;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose one argument for a dedicated schema directory is that theoretically a data structure could be independent of the actions? So xpm_ruby/job.rb is a module containing job related functions, but it is not a class per se. Theoretically any module could access any schema (so one of the calls on client, might use the job schema).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge this for now, we can always move it later (pending a discussion).

Copy link
Contributor

@bedrock-adam bedrock-adam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Tony 👍

Check out the example of defining the schema files relative to the module instead of a parallel hierarchy but don't let it hold anything up too much 🚀

@abreckner abreckner merged commit 6306f4d into master Apr 30, 2020
@abreckner abreckner deleted the dry-types-job branch May 1, 2020 05:14
lankz pushed a commit that referenced this pull request Jun 10, 2025
* Add dry types gem and Job::Add schema

* Add function and test for add job

* use string keys instead of symbol keys
lankz pushed a commit that referenced this pull request Jun 10, 2025
* Add dry types gem and Job::Add schema

* Add function and test for add job

* use string keys instead of symbol keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants