class Dbsketch::Model::Database

Attributes

items[R]

Public Class Methods

new() click to toggle source
# File lib/dbsketch/model/database.rb, line 17
def initialize
        @items = []
end

Public Instance Methods

[](item_name) click to toggle source
# File lib/dbsketch/model/database.rb, line 69
def [] item_name
        ### Preconditions
        raise ArgumentError, "item_name is not a String" unless item_name.is_a? String
        ###
        item = @items.find { |t| t.name.downcase == item_name.downcase }
        raise ModelError, "item #{item_name} not found in database" if nil == item
        item
end
add(object) click to toggle source
# File lib/dbsketch/model/database.rb, line 23
def add object
        objects = object.is_a?(Array) ? object : [object]
        ### Preconditions
        objects.each_with_index do |o, index|
                raise ArgumentError, "object n°#{index + 1} is not a Dbsketch::Model::CustomCode, Index, Operation, Table nor View" unless o.is_a? CustomCode or o.is_a? Index or o.is_a? Operation or o.is_a? Table or o.is_a? Trigger or o.is_a? View
                raise ModelError, "object #{o.name} already exists" if nil != (@items.find { |i| i.name.downcase == o.name.downcase })
        end
        ###
        @items = @items + objects
end
custom_code() click to toggle source
# File lib/dbsketch/model/database.rb, line 38
def custom_code
        get_by_class CustomCode
end
get_by_class(given_class) click to toggle source
# File lib/dbsketch/model/database.rb, line 34
def get_by_class given_class
        @items.select { |i| i.is_a? given_class }
end
has_item?(item_name) click to toggle source
# File lib/dbsketch/model/database.rb, line 62
def has_item? item_name
        ### Preconditions
        raise ArgumentError, "item_name is not a String" unless item_name.is_a? String
        ###
        nil != @items.find { |t| t.name.downcase == item_name.downcase }
end
indexes() click to toggle source
# File lib/dbsketch/model/database.rb, line 42
def indexes
        get_by_class Index
end
operations() click to toggle source
# File lib/dbsketch/model/database.rb, line 46
def operations
        get_by_class Operation
end
order_items!() click to toggle source
# File lib/dbsketch/model/database.rb, line 78
def order_items!
        @items.map! { |i| i.reset_order!; i }
        @items.map! { |i| i.compute_order!; i }
        @items.sort! { |a,b| (a.order != b.order) ? (a.order <=> b.order) : (a.name <=> b.name) }
end
tables() click to toggle source
# File lib/dbsketch/model/database.rb, line 50
def tables
        get_by_class Table
end
triggers() click to toggle source
# File lib/dbsketch/model/database.rb, line 54
def triggers
        get_by_class Trigger
end
views() click to toggle source
# File lib/dbsketch/model/database.rb, line 58
def views
        get_by_class View
end