require "pg_graph/version" require "bigdecimal" require "date" require "boolean" require "constrain" require "developer_exceptions" require "hash_tree" require "ext/meta.rb" require "ext/module.rb" require "pg_graph/version.rb" require "pg_graph/inflector.rb" require "pg_graph/reflector.rb" require "type/type.rb" require "type/read.rb" require "type/dump_type.rb" require "data/data.rb" require "data/association.rb" require "data/value.rb" require "data/dimension.rb" require "data/read.rb" require "data/render.rb" module PgGraph include DeveloperExceptions class Error < StandardError; end # The supported ruby classes RUBY_CLASSES = Inflector::SUPPORTED_RUBY_CLASSES module Type # :call-seq: # new(meta, reflect = nil) # new(pg_conn, reflect = nil) # # The +reflections+ argument can be a Reflector object, an yaml array, a # file name, a PgConn object, or nil. If +reflections+ is a PgConn object, # the +schema+ argument should be set to the schema containing the # 'reflections' table. The +ignore+ option is a list of schema names to # exclude from the type system # # Note that together with ::=== and Database#is_a? this makes # Type::Database pretend it is an instance of the Type module # def self.new(arg, reflections = nil, schema = nil, ignore: []) constrain arg, PgMeta, PgConn constrain reflections, Reflector, Array, String, PgConn, NilClass meta = case arg when PgMeta; arg when PgConn; PgMeta.new(arg) end reflector = case reflections when Reflector; reflections when Array; Reflector.load_yaml(reflections) when String; Reflector.load_file(reflections) when PgConn; Reflector.load_table(reflections, schema) when NilClass; Reflector.new end Database.new(meta.name, reflector).read(meta, ignore: ignore) end # Make the Type module pretend to have Database object instances def self.===(element) element.is_a?(PgGraph::Type::Database) or super end class Database # :call-seq: # instantiate() # instantiate(hash) # instantiate(yaml) # instantiate(pg_conn) # def instantiate(arg = nil) constrain arg, NilClass, Hash, PgConn Data.new(self, arg) end # Let Type::Database objects pretend to be-a module Type object def is_a?(arg) arg == PgGraph::Type || super end end end module Data # :call-seq: # new(type, hash = {}) # new(type, yaml = {}) # new(type, pg_conn = nil) # # Note that together with ::=== and Data::Database#is_a? this makes # Data::Database pretend it is an instance of the Data module def self.new(type, arg) constrain type, PgGraph::Type constrain arg, Hash, PgConn, NilClass Database.new(type, arg) end # Make the Data module pretend to have Database object instances def self.===(element) element.is_a?(PgGraph::Data::Connection) or super end class Database # Let Data::Database objects pretend to be-a module Type object def is_a?(arg) arg == PgGraph::Data || super end end end # Non-public namespace module PrivatePgGraph # Note that this changes the +args+ argument def self.extract_reflections(args) if args.last.is_a?(Hash) reflections = args.last.delete(:reflections) || [] args.pop if args.last.empty? && !reflections.empty? reflections else [] end end end end