Class: ActiveRecord::Base

Inherits:
Object show all
Extended by:
RDL::Annotate, RDL::RDLAnnotate
Defined in:
lib/types/rails/active_record/model_schema.rb,
lib/types/rails/active_record/comp_types.rb

Class Method Summary collapse

Methods included from RDL::RDLAnnotate

rdl_attr_accessor_type, rdl_attr_reader_type, rdl_attr_writer_type

Methods included from RDL::Annotate

attr_accessor_type, attr_reader_type, attr_writer_type, post, pre, rdl_alias, readd_comp_types, type, type_params, var_type

Class Method Details

.access_output(trec, targs) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/types/rails/active_record/comp_types.rb', line 27

def self.access_output(trec, targs)
  case trec
  when RDL::Type::NominalType
    tname = trec.name.to_sym
    tschema = RDL.type_cast(RDL::Globals.ar_db_schema[tname].params[0], "RDL::Type::FiniteHashType", force: true).elts
    raise "Schema not found." unless tschema
    arg = targs[0]
    case arg
    when RDL::Type::SingletonType
      col = arg.val
      ret = tschema[col]
      ret = RDL::Globals.types[:nil] unless ret
      return ret
    else
      raise "TODO"
    end
  else
    raise 'unexpected type'
  end
end

.uc_first_arg(trec) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/types/rails/active_record/comp_types.rb', line 49

def self.uc_first_arg(trec)
  case trec
  when RDL::Type::NominalType
    tname = trec.name.to_sym
    tschema = RDL.type_cast(RDL::Globals.ar_db_schema[tname].params[0], "RDL::Type::FiniteHashType", force: true).elts
    raise "Schema not found." unless tschema
    typs = RDL.type_cast(tschema.keys, "Array<Symbol>", force: true).reject { |k| k == :__associations}.map { |k| RDL::Type::SingletonType.new(k) }
    return RDL::Type::UnionType.new(*RDL.type_cast(typs, "Array<RDL::Type::Type>"))
  else
    raise "unexpected type"
  end
end

.uc_second_arg(trec, targs) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/types/rails/active_record/comp_types.rb', line 63

def self.uc_second_arg(trec, targs)
  case trec
  when RDL::Type::NominalType
    tname = trec.name.to_sym
    tschema = RDL.type_cast(RDL::Globals.ar_db_schema[tname].params[0], "RDL::Type::FiniteHashType", force: true).elts
    raise "Schema not found." unless tschema
    raise "Unexpected first arg type." unless targs[0].is_a?(RDL::Type::SingletonType) && RDL.type_cast(targs[0], "RDL::Type::SingletonType<Object>").val.is_a?(Symbol)
    return tschema[RDL.type_cast(targs[0], "RDL::Type::SingletonType<Symbol>").val]
  else
    raise "unexpected type"
  end
end