module Entity::REST

Constants

REST_ENTITIES

Public Class Methods

clean_element(elem) click to toggle source

{{{ MISC

# File lib/rbbt/rest/entity/rest.rb, line 15
def self.clean_element(elem)
  elem.gsub('&', '--AND--').gsub('/', '-..-').gsub("|", '-...-').gsub('%', 'o-o').gsub('[','(.-(').gsub(']',').-)')
end
entity_action_url(entity, type, action, params = {}) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 91
def self.entity_action_url(entity, type, action, params = {})
  url = File.join('/', 'entity_action', Entity::REST.clean_element(type.to_s), action.to_s, Entity::REST.clean_element(entity))
  url << "?" << Misc.hash2GET_params(params) if params.any?
  url
end
entity_list_action_url(list, type, action, params) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 101
def self.entity_list_action_url(list, type, action, params)
  url = File.join('/', 'entity_list_action', Entity::REST.clean_element(type.to_s), action.to_s, Entity::REST.clean_element(list))
  url << "?" << Misc.hash2GET_params(params) if params.any?
  url
end
entity_list_url(list, type) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 97
def self.entity_list_url(list, type)
  File.join('/', 'entity_list', Entity::REST.clean_element(type.to_s), Entity::REST.clean_element(list))
end
entity_map_action_url(map, type, column, action) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 114
def self.entity_map_action_url(map, type, column, action)
  type = Entity::REST.clean_element(type.to_s)
  column = Entity::REST.clean_element(column)
  map = Entity::REST.clean_element(map)
  File.join('/', 'entity_map_action', type,  column, action, map)
end
entity_map_url(map, type, column) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 107
def self.entity_map_url(map, type, column)
  type = Entity::REST.clean_element(type.to_s)
  column = Entity::REST.clean_element(column)
  map = Entity::REST.clean_element(map)
  File.join('/', 'entity_map', type,  column, map)
end
entity_url(entity, type = nil, params = nil) click to toggle source

{{{ URLS

# File lib/rbbt/rest/entity/rest.rb, line 71
def self.entity_url(entity, type = nil, params = nil)
  if type.nil?
    type = entity.annotation_types.last.to_s
    type << ":" << entity.format if entity.respond_to? :format and entity.format
  end

  if params.nil?
    if entity.respond_to? :entity_link_params
      params = entity.entity_link_params
    else
      params = entity.respond_to?(:info) ? entity.info : {}
    end
  end


  url = File.join('/', 'entity', Entity::REST.clean_element(type.to_s), Entity::REST.clean_element(entity)) 
  url << "?" << Misc.hash2GET_params(params) if params.any?
  url
end
included(base) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 9
def self.included(base)
  REST_ENTITIES << base
end
restore_element(elem) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 19
def self.restore_element(elem)
  CGI.unescape(CGI.unescape(elem.gsub('--AND--', '&').gsub('-..-', '/').gsub('-...-', '|').gsub('o-o', '%').gsub('(.-(','[').gsub(').-)',']')))
end
setup(mod) click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 23
def self.setup(mod)
  mod.module_eval do
    include Entity::REST
  end
end

Public Instance Methods

base_type() click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 37
def base_type
  annotation_types.select{|mod| mod.include? Entity::REST }.first.to_s
end
entity_type() click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 48
def entity_type
  entity_type = self.respond_to?(:format) ? [base_type, format].compact.join(":") : base_type
end
klasses() click to toggle source
# File lib/rbbt/rest/entity/rest.rb, line 41
def klasses
  klasses = []
  klasses << base_type.to_s if base_type
  klasses << format if self.respond_to? :format and format
  klasses.collect{|klass| klass.gsub(/[^\w]/, '_') }
end