Sha256: f9e0fee1e893e243bb556aee6d9542f7391d8d6fc1aa4c2e47ce3b6f04f83393

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Saml
  module Kit
    module Cli
      class YamlRegistry < ::Saml::Kit::DefaultRegistry
        def initialize(path)
          @items = YAML::Store.new(path)
        end

        def register(metadata)
          with_transaction do |db|
            db[metadata.entity_id] = metadata.to_xml
          end
          metadata
        end

        def metadata_for(entity_id)
          with_transaction do |db|
            xml = db[entity_id]
            return nil if xml.nil?
            Saml::Kit::Metadata.from(xml)
          end
        end

        def each
          with_transaction do |db|
            db.roots.each do |key|
              yield metadata_for(key)
            end
          end
        end

        private

        def with_transaction
          if @in_transaction
            yield @items
          else
            @items.transaction do
              begin
                @in_transaction = true
                yield @items
              ensure
                @in_transaction = false
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saml-kit-cli-0.3.6 lib/saml/kit/cli/yaml_registry.rb
saml-kit-cli-0.3.5 lib/saml/kit/cli/yaml_registry.rb
saml-kit-cli-0.3.4 lib/saml/kit/cli/yaml_registry.rb
saml-kit-cli-0.3.3 lib/saml/kit/cli/yaml_registry.rb