Project

ensconce

0.0
No commit activity in last 3 years
No release in over 3 years
Wraps connections to Personal Data Stores, to allow data stores to changed. For example, to aid testing or swap data store provider
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

ensconce¶ ↑

Ensconce provides a common interface to data stores. The connection between Ensconce::DataStore and a data store provider is configured via an adapter

YAML file data store¶ ↑

user = User.new(:id => 'user_1')
DataStore.adapter = YamlFileAdapter.config(:file => 'path/to/file.yml')
data_store = DataStore.open user

Opens a data store from the file specified within the adapter config. The store could look something like this:

user_1:
  some_field: x

We can get and set ‘some_field’ like this

data_store['some_field'] == 'x'   # returns true
data_store['some_field'] = 'y'
data_store.save

The file will then look like this:

user_1:
  some_field: y

Mydex data source¶ ↑

DataStore.adapter = MydexAdapter.config(
  url: <mydex url>
  api_key: <your api key>
)

user = MydexUser.new(
  key: <from your user's connection settings>
  con_id: <from your user's connection settings>
  id: <from your user's connection settings>
)

settings.yml is provided as a place where you can enter valid sandbox setting, and these will be used when testing. The test connection needs access to the sandbox user’s personal_details area.

We can then get the mydex user’s data like this:

data_store = DataStore.open(user, :data_set => 'field_ds_personal_details')
data_store['first_name'] --> Mydex user's first name

Updating data works just as it does for the YAML example:

data_store['first_name'] = 'Robert'
data_store.save

This will write a new first name to the Mydex user’s personal_details.

Key mappers¶ ↑

Note that in Mydex the first name field is actually ‘field_personal_fname’. Ensconce provides key mappers that allow you to use more generic names for fields, thereby making it easier to swap data stores.