Sha256: b52ac16624ca02f14486bbab2e755cd667850449ad5a03883166da9dbbddc5b8
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
require 'multi_json' require 'iron_hide' require 'iron_hide/storage' require 'typhoeus' module IronHide class Storage class CouchdbAdapter # @option opts [String] :resource *required* # @option opts [String] :action *required* # @return [Array<Hash>] array of canonical JSON representation of rules def where(opts = {}) self["#{opts.fetch(:resource)}::#{opts.fetch(:action)}"] end private # Implements an interface that makes selecting rules look like a Hash: # @example # { # 'com::test::TestResource::read' => { # ... # } # } # adapter['com::test::TestResource::read'] # #=> [Array<Hash>] # # @param [Symbol] val # @return [Array<Hash>] array of canonical JSON representation of rules def [](val) response = couchd_db_rules(val) if response.response_code == 200 MultiJson.load(response.response_body)["rows"].reduce([]) do |rval, row| rval << row["value"] end else # Do Something end end def couchd_db_rules(val) Typhoeus.get( "#{server}/#{database}/_design/rules/_view/resource_rules?key=\"#{val}\"" ) end def server IronHide.configuration.couchdb_server end def database IronHide.configuration.couchdb_database end end end end # Add adapter class to IronHide::Storage IronHide::Storage::ADAPTERS.merge!(couchdb: :CouchdbAdapter) # Add default configuration variables IronHide.configuration.add_configuration(couchdb_server: 'http://127.0.0.1:5984', couchdb_database: 'rules')
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
iron_hide-storage-couchdb_adapter-0.0.1 | lib/iron_hide/storage/couchdb_adapter.rb |