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>
)
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.
Testing ensconce
To test this applications mydex connection, a settings.yml needs to be added at the root of the ensconce code. This file should have this format:
mydex:
url: 'https://sbx-api.mydex.org/'
key: <key from sandbox connection>
api_key: <your mydex api key>
con_id: <con_id from sandbox connection>
id: id <from sandbox connection>