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

Required configuration values:

api_url - url of server managing the Permissions repo

access_token - token for authorizing access to the server

Use

If you use default config files (see Permissions section below) you can simply do:

data = DataGuru::Client.new(api_url: <URL>, access_token: <TOKEN>)

# get collections
data.members.all
data.projects.all
data.github_teams.all
data.google_groups.all
data.rollbar_teams.all
data.toggl_teams.all

# find in collections by attribute
data.projects.find{ |project| project.display_name == 'Some project' }
data.members.find{ |member| member.github == 'example' }

# filter collections by attributes
data.members.select{ |member| member.external }
data.members.select{ |member| member.public_key.nil? }.count

# select key names of all github teams a member belongs to
member = data.members.first
data.github_teams.select{ |team| team.members.include?(member.id) }.map(&:id)

The collections include Enumerable module so that you can filter models by attributes easily (data.members.select{ |member| member.some_method }).

You can refresh repo and storage at any time:

data = DataGuru::Client.new
data.refresh

On a single model you can do:

data = DataGuru::Client.new
member = data.members.all.first

# to get list of member attributes
member.attributes

# to get list of permitted and required attributes (see Permissions section below)
member.permitted_attributes
member.required_attributes

# check if member has all required attributes set with valid datatypes
member.valid?
member.missing_attributes
member.invalid_data_type_attributes

Each model has a set of getter methods (permitted_attributes), so for example you can do member.github to get just the github membername. Each model also has id method which returns the name of the file the member is stored in, for example it will return john.doe for the member in the file john.doe.yml.

To check if files in your Permissions repo contain valid information you can run:

DataGuru::Client.new.invalid_values

You will get a hash with names of invalid files and values which are missing or have invalid datatype:

# {
#   "john.doe.yml" => {
#     "missing_attributes" => [:emails, :external],
#     "invalid_data_type_attributes" => [:github]
#   }
# }

You can also check invalid values of particular collection:

DataGuru::Client.new.invalid_values("users")

If you want to check a particular value in a collection, you need to specify collection name and value name:

DataGuru::Client.new.invalid_values("users", "email")

You will get an array containing names of files from "users" collection which have invalid "email" value:

# ["john.doe.yml", "jane.foe.yml"]

You can also pass parameters as symbols:

DataGuru::Client.new.invalid_values(:users, :email)

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 member.yml, project.yml, github_team.yml. In these files you specify attributes of each model with information about whether they are required, what is the default value, and what is the datatype.

---
emails:
  default_value: []
  required: true
  value_type: array
external:
  default_value: false
  required: true
  value_type: boolean
github:
  default_value:
  required: true
  value_type: string
name:
  default_value:
  required: true
  value_type: string
public_key:
  default_value:
  required: true
  value_type: string

The methods permitted_attributes and required_attributes return array of specified attributes.

All files should stay in appropriate directories, e.g. store members in members/ directory.

For more details see the sample permissions repo.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run 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.