Module: SDL

Defined in:
lib/sdl.rb,
lib/sdl/enum.rb,
lib/sdl/name.rb,
lib/sdl/field.rb,
lib/sdl/model.rb,
lib/sdl/types.rb,
lib/sdl/parser.rb,
lib/sdl/schema.rb,
lib/sdl/version.rb,
lib/sdl/attribute.rb,
lib/sdl/attachment.rb,
lib/sdl/association.rb

Defined Under Namespace

Classes: Association, Attachment, Attribute, CircularDependencyError, Enum, Error, Field, Model, Name, ParseError, Parser, Schema

Constant Summary collapse

SCALAR_TYPES =
%i[
  id
  string
  boolean
  integer
  float
  decimal
  date
  datetime
  text
  binary
]
TYPES =
SCALAR_TYPES + %i[
  enum
  belongs_to
  has_one
  has_many
  has_one_attached
  has_many_attached
]
VERSION =
"0.0.0"

Class Method Summary collapse

Class Method Details

.define(&block) ⇒ Schema

Defines a new schema. The block will be evaluated in the context of a Schema

Examples:

SDL.define do
  model :user do
    attribute :name, :string
  end
end

Returns:



28
29
30
# File 'lib/sdl.rb', line 28

def self.define(&block)
  Schema.new(&block)
end

.load_file(file) ⇒ Schema

Loads a schema from a file. The contents of the file will be evaluated in the context of a Schema

Examples:

SDL.load_file("schema.rb")

Returns:



38
39
40
41
42
# File 'lib/sdl.rb', line 38

def self.load_file(file)
  schema = Schema.new
  schema.instance_eval(File.read(file), file)
  schema
end

.parse(name, fields) ⇒ Model

Constructs a model from command-line arguments

Examples:

SDL.parse("user", ["name", "email:required:unique"])

Returns:

Raises:

See Also:



51
52
53
54
55
# File 'lib/sdl.rb', line 51

def self.parse(name, fields)
  parser = Parser.new
  fields = fields.map { |field| parser.parse(field) }
  Model.new(name, fields: fields)
end