Studitemps::Utils

Shared utils for Studitemp's Ruby projects.

Status

TravisCI codecov Depfu Maintainability Inline docs

Installation

Add this line to your application's Gemfile:

gem 'studitemps-utils'

And then execute:

$ bundle

Or install it yourself as:

$ gem install studitemps-utils

URI

An Studitemps Utils URI references similar to a normal URI a specific resource. It contains at least a schema but most of the time when used to reference a resource it also has a context, resource, and an id.

Example: com.example:billing:invoice:R422342

  • schema: com.example - Some kind of schema to make URI globally unique.
  • context: billing - The context the URI (and the resource) belongs to.
  • resource: invoice - The resource type.
  • id: R422342 - The resource id.

Usage

require 'studitemps/utils/uri'

MyBaseURI = Studitemps::Utils::URI.build(schema: 'com.example')
InvoiceURI = Studitemps::Utils::URI.build(from: MyBaseURI, context: 'billing', resource: 'invoice')

uri = InvoiceURI.new(id: 'R422342') # => #<InvoiceURI 'com.example:billing:invoice:R422342'>
uri.to_s # => 'com.example:billing:invoice:R422342'

InvoiceURI.build('com.example:billing:invoice:R422342') # => #<InvoiceURI 'com.example:billing:invoice:R422342'>
InvoiceURI.build(id: 'R422342') # => #<InvoiceURI 'com.example:billing:invoice:R422342'>
InvoiceURI.build(uri) # => #<InvoiceURI 'com.example:billing:invoice:R422342'>

Extensions

Extensions add additional functionality to URIs. They can be used by requiring them before building the URI classes.

require 'studitemps/utils/uri/extensions/serialization'

MyBaseURI = Studitemps::Utils::URI.build(schema: 'com.example')
uri = MyBaseURI.new(context: 'billing', resource: 'invoice', id: 'R422342')

MyBaseURI.dump(uri) # => 'com.example:billing:invoice:R422342'
MyBaseURI.load('com.example:billing:invoice:R422342') # =>  #<MyBaseURI 'com.example:billing:invoice:R422342'>

Available Extensions

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/STUDITEMPS/studitemps-utils.

License

The gem is available as open source under the terms of the MIT License.