README.md in pears-0.0.7 vs README.md in pears-0.0.8

- old
+ new

@@ -20,13 +20,37 @@ $ gem install pears ## Usage -Configuration is loaded via the provider setting. +Examples: +```ruby +# You can load a dynamic config file like this +dynamic_config = Pears.subject(:settings) do |provider| + provider.subscription do + provider.remote_file "https://raw.githubusercontent.com/codefresh-io/yaml-examples/master/codefresh-build-1.yml" + end +end +# You can "Cascade" data like this +cascading_config = Pears.subject(:settings) do |provider| + provider.local_file Rails.root.join('config', 'settings.concrete.yml') # defines foo: 'foo' + provider.local_file Rails.root.join('config', 'settings.default.yml') # defines foo: 'bar', baz: 'baz' +end + +cascading_config[:foo] # => foo +cascading_config[:baz] # => baz + +# And you can combine these +combined_config = Pears.subject(:settings) do |provider| + provider.subscription { provider.remote_file "https://admin/configuration.yml" } + provider.local_file Rails.root.join('config', 'default.yml') +end +``` + + ## Terminology - A Subject is a grouping of configuration items with a single interface - A Subject contains at least a single "Layer" that wraps a "Provider" - A Provider is an adapter(YAML OR REDIS). @@ -35,33 +59,69 @@ ##### Providers: - LocalFile - read a yaml file identified by a path into a "Subject" - RemoteFile - read a yaml file identified by a URI into a "Subject" - Subscription - Read a yaml file identified by a URI as a segment and update it whenever the the provided redis channel gets an update. -- ENV - read the ENV and overwrite keys found on lower layers of the segment. ** -- LOCO - read a loco file into a segment. ** -** Nice to have +You can create a custom povider like this: +```ruby +class GcloudProvider < Pears::Provider::LocalFile + def initialize + @data = parse_yaml Faraday.get(url, {}, authorization: token ) + end + private + + def url + 'https://velogica-portal-admin.ey.r.appspot.com/settings/' \ + "#{Rails.application.secrets.settings_file}" + end + + def token + path = 'http://metadata.google.internal/computeMetadata/v1/instance/' + + 'Bearer ' + Faraday.get(path, {}, { metadata_flavor: 'Google' }).body + end +end +``` + +And register it like this: + +```ruby +# config/initializers/pears.rb +Pears::Provider::Builder.enable_provider Pears::GcloudProvider +``` + + ## Todo -- Figure out if subscription should be a providerof maybe something else. -- Add Loco as a provider. -- Add ENV as a provider. -- Add Redis as a provider. -- Figure out if there is a sensible tie in with kubernetes. -- Add support for different file-types. -- Add different ways to trigger updates from redis subscriptions. (like hand fired events?) + ## 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Future + +- Factor subject as a distinct, non-provider entitity. +- Add Loco as a provider. +- Add ENV as a provider. +- Figure out if there is a sensible tie in with kubernetes. +- Add support for different file-types. +- Add different ways to trigger updates from redis subscriptions. + +We want to add the following providers: +- ENV - read the ENV and overwrite keys found on lower layers of the segment. ** +- LOCO - read a loco file into a segment. +- Redis - consume data drom a redis key. + + ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pears. +Hit me up on slack, jira or Bitbucket! ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).