Sha256: 4cbac7f0298340970fae43dc0f866fa899714194ca11b771b6c18b61807aebe9

Contents?: true

Size: 861 Bytes

Versions: 2

Compression:

Stored size: 861 Bytes

Contents

require 'sparrow/strategies/json_format_strategies/default_json_format_strategy'
require 'active_support/core_ext/object/blank'

module Sparrow
  module Strategies
    class JsonFormatStrategy
      def initialize(*args)

      end

      def self.register_json_format(*args)
        init(args)
        @@json_format_strategies << self.new(args)
      end

      def self.convert(body)
        strategy = json_format_strategies.select do |strategy|
          strategy.match?(body)
        end.first
        strategy.convert(body)
      end

      private
      def self.init(*args)
        @@json_format_strategies ||= Array.new(args)
      end

      def self.json_format_strategies
        init
        default = Sparrow::Strategies::DefaultJsonFormatStrategy.instance
        @@json_format_strategies.reject(&:blank?) + [default]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp-sparrow-0.0.12 lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb
cp-sparrow-0.0.11 lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb