lib/csvlint/schema.rb in csvlint-0.3.3 vs lib/csvlint/schema.rb in csvlint-0.4.0
- old
+ new
@@ -14,10 +14,12 @@
reset
end
class << self
+ extend Gem::Deprecate
+
def from_json_table(uri, json)
fields = []
json["fields"].each do |field_desc|
fields << Csvlint::Field.new( field_desc["name"] , field_desc["constraints"],
field_desc["title"], field_desc["description"] )
@@ -27,24 +29,34 @@
def from_csvw_metadata(uri, json)
return Csvlint::Csvw::TableGroup.from_json(uri, json)
end
+ # Deprecated method signature
def load_from_json(uri, output_errors = true)
+ load_from_uri(uri, output_errors)
+ end
+ deprecate :load_from_json, :load_from_uri, 2018, 1
+
+ def load_from_uri(uri, output_errors = true)
+ load_from_string(uri, open(uri).read, output_errors)
+ rescue OpenURI::HTTPError, Errno::ENOENT => e
+ raise e
+ end
+
+ def load_from_string(uri, string, output_errors = true)
begin
- json = JSON.parse( open(uri).read )
+ json = JSON.parse( string )
if json["@context"]
uri = "file:#{File.expand_path(uri)}" unless uri.to_s =~ /^http(s)?/
return Schema.from_csvw_metadata(uri,json)
else
return Schema.from_json_table(uri,json)
end
rescue TypeError => e
# NO IDEA what this was even trying to do - SP 20160526
rescue Csvlint::Csvw::MetadataError => e
- raise e
- rescue OpenURI::HTTPError, Errno::ENOENT => e
raise e
rescue => e
if output_errors === true
STDERR.puts e.class
STDERR.puts e.message