class Dgrid::API::Workspace

Attributes

connection[RW]
description[RW]
id[RW]
name[RW]

Public Class Methods

new(connection, name='DEFAULT WORKSPACE', description = "") click to toggle source
# File lib/dgrid/api/workspace.rb, line 12
def initialize(connection, name='DEFAULT WORKSPACE', description = "")
  @id = nil
  @connection = connection
  @name = name
  @item_ids = {} # lens_id => [item_id]
  @entity_cache = Cache.new
end
pluralized() click to toggle source
# File lib/dgrid/api/workspace.rb, line 20
def self.pluralized
  'workspaces'
end
singular() click to toggle source
# File lib/dgrid/api/workspace.rb, line 24
def self.singular
  name.split('::').last.downcase
end

Public Instance Methods

add_entity(entity) click to toggle source
# File lib/dgrid/api/workspace.rb, line 159
def add_entity(entity)
  if entity.new_record?
    entity = connection.create_entity(entity,self.id)
  end
  if !entity.in_workspace?(self)
    entity.add_workspace(self)
  end
  @entity_cache.invalidate(entity.class)
  entity
end
add_incident(incident, item = nil) click to toggle source
# File lib/dgrid/api/workspace.rb, line 54
def add_incident(incident, item = nil)
  if item
    raise "Cannot add an Incident in a Workspace unless owning Item is already in the Workspace" unless item.in_workspace?(self)
    raise "Cannot add an Incident to an unsaved Item" if item.new_record?
  end
  if incident.new_record?
    incident = connection.create_entity(incident, self.id)
  end
  if !incident.in_workspace?(self)
    incident.add_workspace(self)
  end
  if item
    connection.subordinate_entity_to_other_entity_in_workspace(incident, item, self.id)
  end
  incident
end
add_item(item) click to toggle source
# File lib/dgrid/api/workspace.rb, line 48
def add_item(item)
  add_entity(item)
end
add_keyword(keyword) click to toggle source
# File lib/dgrid/api/workspace.rb, line 72
def add_keyword(keyword)
  add_entity(keyword)
end
add_organization(organization) click to toggle source
# File lib/dgrid/api/workspace.rb, line 43
def add_organization(organization)
  add_entity(organization)
end
add_person(person) click to toggle source
# File lib/dgrid/api/workspace.rb, line 33
def add_person(person)
  add_entity(person)
end
add_place(place) click to toggle source
# File lib/dgrid/api/workspace.rb, line 38
def add_place(place)
  add_entity(place)
end
backup() click to toggle source
# File lib/dgrid/api/workspace.rb, line 528
def backup()
  backup = Backup.create(self)
end
clone_members_into(other_workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 533
def clone_members_into(other_workspace)
  backup().restore_into(other_workspace)
end
create_item(options = {}) { |item| ... } click to toggle source
# File lib/dgrid/api/workspace.rb, line 100
def create_item(options = {}, &block)
  item = add_item(Dgrid::API::Item.new(options))
  yield item if block_given?
  item
end
create_organization(options = {}) { |organization| ... } click to toggle source
# File lib/dgrid/api/workspace.rb, line 94
def create_organization(options = {}, &block)
  organization = add_organization(Dgrid::API::Organization.new(options))
  yield organization if block_given?
  organization
end
create_person(options = {}) click to toggle source

TODO auto-generate this templatesque bullshit

# File lib/dgrid/api/workspace.rb, line 84
def create_person(options = {})
  person = add_person(Dgrid::API::Person.new(options))
  person
end
create_place(options = {}) click to toggle source
# File lib/dgrid/api/workspace.rb, line 89
def create_place(options = {})
  place = add_place(Dgrid::API::Place.new(options))
  place
end
get_entities(klass) click to toggle source
# File lib/dgrid/api/workspace.rb, line 170
def get_entities(klass)
  pluralized_name = klass.pluralized
  return @entity_cache.get(klass) if @entity_cache.include?(klass)
  construction_fields = klass.db_fields
  entities_params = connection.get_in_workspace(self.id, pluralized_name)
  entities = []
  entities_params.each do |entity_params|
    construction_params, other_params = split_hash(entity_params, construction_fields)
    entity = klass.new(change_string_keys_to_symbol_keys(construction_params))
    entity.add_workspace(self)
    entities <<  entity
  end
  @entity_cache.store(klass,entities)
end
incident_ids_in_item(item) click to toggle source
# File lib/dgrid/api/workspace.rb, line 155
def incident_ids_in_item(item)
  incident_ids = connection.get_incidents_in_item(self.id, item.id)
end
incidents() click to toggle source
# File lib/dgrid/api/workspace.rb, line 141
def incidents
  get_entities(Incident)
end
invalidate_cache(klass) click to toggle source
# File lib/dgrid/api/workspace.rb, line 185
def invalidate_cache(klass)
  @entity_cache.invalidate(klass)
end
item_ids_in_lens(lens) click to toggle source
# File lib/dgrid/api/workspace.rb, line 150
def item_ids_in_lens(lens)
  item_ids = connection.get_items_in_lens(self.id, lens.id)
end
items() click to toggle source
# File lib/dgrid/api/workspace.rb, line 119
def items
    get_entities(Item)
end
keywords() click to toggle source
# File lib/dgrid/api/workspace.rb, line 145
def keywords
  get_entities(Keyword)
end
lenses() click to toggle source
# File lib/dgrid/api/workspace.rb, line 137
def lenses
  get_entities(Lens)
end
organizations() click to toggle source
# File lib/dgrid/api/workspace.rb, line 129
def organizations
    get_entities(Organization)
end
people() click to toggle source
# File lib/dgrid/api/workspace.rb, line 122
def people
    get_entities(Person)
end
places() click to toggle source
# File lib/dgrid/api/workspace.rb, line 125
def places
    get_entities(Place)
end
subordinate_entity_to_other_entity(entity, other) click to toggle source
# File lib/dgrid/api/workspace.rb, line 76
def subordinate_entity_to_other_entity(entity, other)
  connection.subordinate_entity_to_other_entity_in_workspace(entity, other, self.id)
  @entity_cache.invalidate(Link)
end
type() click to toggle source
# File lib/dgrid/api/workspace.rb, line 28
def type
  self.class.name.split('::').last
end