lib/syncano/schema.rb in syncano-4.0.0.alpha1 vs lib/syncano/schema.rb in syncano-4.0.0.alpha2
- old
+ new
@@ -1,37 +1,28 @@
require_relative './schema/attribute_definition'
require_relative './schema/resource_definition'
+require_relative './schema/endpoints_whitelist'
+require 'singleton'
+
module Syncano
class Schema
- SCHEMA_PATH = 'schema/'
attr_reader :schema
- def initialize(connection)
- self.connection = connection
- load_schema
+ def self.schema_path
+ "/#{Syncano::Connection::API_VERSION}/schema/"
end
- def process!
- schema.each do |name, raw_resource_definition|
- resource_definition = Syncano::Schema::ResourceDefinition.new(name, raw_resource_definition)
- resource_class = ::Syncano::Resources.define_resource_class(resource_definition)
-
- if resource_definition[:collection].present? && resource_definition[:collection][:path].scan(/\{([^}]+)\}/).empty?
- self.class.generate_client_method(name, resource_class)
- end
- end
+ def initialize(connection = ::Syncano::Connection.new)
+ self.connection = connection
end
- private
-
attr_accessor :connection
- attr_writer :schema
- def load_schema
- raw_schema = connection.request(:get, SCHEMA_PATH)
+ def definition
+ raw_schema = connection.request(:get, self.class.schema_path)
resources = {}
raw_schema.each do |resource_schema|
class_name = resource_schema['name']
@@ -68,19 +59,9 @@
resources[class_name][:custom_methods] << endpoint_data
end
end
end
- self.schema = resources
- end
-
- class << self
- def generate_client_method(resource_name, resource_class)
- method_name = resource_name.tableize
-
- ::Syncano::API.send(:define_method, method_name) do
- ::Syncano::QueryBuilder.new(connection, resource_class)
- end
- end
+ resources
end
end
end
\ No newline at end of file