Method: Acter.load_schema_data

Defined in:
lib/acter.rb

.load_schema_data(path = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acter.rb', line 10

def load_schema_data(path = nil)
  path ||= Pathname.glob("schema.{json,yml}").first or raise NoSchema
  if path.is_a?(String)
    uri = URI(path)
    source = uri.scheme ? uri : Pathname.new(path)
  elsif path.respond_to?(:read) && path.respond_to?(:to_s)
    source = path
  else
    raise ArgumentError, "Argument to load_schema must be a String or a Pathname-like object"
  end
  if source.to_s =~ /\.ya?ml$/
    YAML.load(source.read)
  else
    MultiJson.load(source.read)
  end
end