DataGuru
Manage configuration stored as JSON data in DataGuru-API server.
Installation
Add this line to your application's Gemfile:
gem 'data_guru'
And then execute:
$ bundle
Or install it yourself as:
$ gem install data_guru
Configuration
Create config file in your app:
# app/config/initializers/data_guru.rb
DataGuru.configure do |config|
config.api_url = 'url of api server'
config.access_token = 'access token'
end
Possible configuration values:
api_url - [mandatory] api server where data from Permissions is stored
access_token - [mandatory] token needed for verifying access to api server
Usage
If you use default config files (see Permissions section below) you can simply do:
data = DataGuru::Client.new
# get collections
data.users.all
data.projects.all
data.github_teams.all
data.google_groups.all
data..all
data.toggl_teams.all
# find in collections by attribute
data.projects.find{ |project| project.display_name == 'Some project' }
data.users.find{ |user| user.github == 'example' }
# filter through collections by attributes
data.users.select{ |user| user.external }
data.users.select{ |user| user.public_key.nil? }.count
# select key names of all github teams user belongs to
user = data.users.first
data.github_teams.select{ |team| team.members.include?(user.id) }.map(&:id)
The collections have Enumerable module included so you can filter models by attributes easily (data.users.select{ |user| user.some_method })
You can refresh repo and storage at any time, just do:
data = DataGuru::Client.new
data.refresh
On a single model you can do:
data = DataGuru::Client.new
user = data.users.all.first
# to get list of user attributes
user.attributes
# to get list of permitted and required attributes (see Permisions section below)
user.permitted_attributes
user.required_attributes
# check if user has all required attributes set
user.valid?
user.missing_attributes
Each model has a set of getter methods (permitted_attributes) so you can for example do user.github to get just the github username of the user.
Each model also has id method which returns the name of the file, for example for the user in a file john.doe.yml will return john.doe.
You can check whether configuration (in your rails app) and model configuration (in your permissions repo) is valid by running DataGuru::Client.new.errors.
Permissions
A sample permissions repo contains a config directory with files like user.yml, project.yml, github_team.yml. In these files you specify attributes for each model with information about whether they are required, what is the default value and what type of value it is.
---
name:
required: true
default_value:
value_type: string
emails:
required: true
default_value:
value_type: array
external:
required: false
default_value: false
value_type: boolean
The methods permitted_attributes and required_attributes returns the array of specified attributes.
All the files should be under the appropriate directory, for example all users under users directory, they can be nested if you want.
For more information see the permissions template repo.
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. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/netguru/data_guru.