class Sparrow::Strategies::JsonFormatStrategy

Superclass for all JSON format strategies. Contains no own instance logic, but keeps track of the registration of all JSON format strategies with its Singleton class methods. @abstract Not exactly a abstract class but contains no own logic but

singleton class methods

Public Class Methods

convert(body) click to toggle source

Start a JSON conversion by its given string @param [Object] body a JSON object representation.

can be any type a JSON format strategy is registered,
i.e. an Array, a String or a RackBody

@return [String] the formatted JSON

# File lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb, line 31
def self.convert(body)
  strategy = json_format_strategies.detect do |strategy_candidate|
    strategy_candidate.match?(body)
  end
  strategy.convert(body)
end
new(*_args) click to toggle source

Empty constructor. Does nothing.

# File lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb, line 12
def initialize(*_args)
end
register_json_format(*args) click to toggle source

Register a new JSON Format strategy @param [Object] args the arguments for the new strategy @return [Array] args the updated registered JSON Format strategies

available
# File lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb, line 20
def self.register_json_format(*args)
  init(args)
  @@json_format_strategies << self.new(args)
end

Private Class Methods

init(*args) click to toggle source
# File lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb, line 38
def self.init(*args)
  @@json_format_strategies ||= Array.new(args)
end
json_format_strategies() click to toggle source
# File lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb, line 43
def self.json_format_strategies
  init
  default = Sparrow::Strategies::DefaultJsonFormatStrategy.instance
  @@json_format_strategies.reject(&:blank?) + [default]
end