Module: Entity::REST
- Defined in:
- lib/rbbt/rest/entity/rest.rb
Constant Summary collapse
- USE_ENSEMBL =
true
- REST_ENTITIES =
[]
Class Method Summary collapse
-
.clean_element(elem) ⇒ Object
{{{ MISC.
- .entity_action_url(entity, type, action, params = {}) ⇒ Object
- .entity_list_action_url(list, type, action, params) ⇒ Object
- .entity_list_url(list, type) ⇒ Object
- .entity_map_action_url(map, type, column, action) ⇒ Object
- .entity_map_url(map, type, column) ⇒ Object
-
.entity_url(entity, type = nil, params = nil) ⇒ Object
{{{ URLS.
- .included(base) ⇒ Object
- .restore_element(elem) ⇒ Object
Instance Method Summary collapse
- #action_link(action, text = nil, options = {}) ⇒ Object
- #base_type ⇒ Object
- #entity_link_params ⇒ Object
- #entity_type ⇒ Object
- #klasses ⇒ Object
-
#link(text = nil, options = {}) ⇒ Object
{{{ LINKS.
- #list_action_link(action, text = nil, id = nil, options = {}) ⇒ Object
- #list_link(text = nil, id = nil, options = {}) ⇒ Object
- #process_link_options(options = {}, include_entity_params = true) ⇒ Object
Class Method Details
.clean_element(elem) ⇒ Object
{{{ MISC
16 17 18 |
# File 'lib/rbbt/rest/entity/rest.rb', line 16 def self.clean_element(elem) elem.gsub('/', '--').gsub('%', 'o-o') end |
.entity_action_url(entity, type, action, params = {}) ⇒ Object
88 89 90 91 92 |
# File 'lib/rbbt/rest/entity/rest.rb', line 88 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) url << "?" << Misc.hash2GET_params(params) if params.any? url end |
.entity_list_action_url(list, type, action, params) ⇒ Object
98 99 100 101 102 |
# File 'lib/rbbt/rest/entity/rest.rb', line 98 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) ⇒ Object
94 95 96 |
# File 'lib/rbbt/rest/entity/rest.rb', line 94 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) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/rbbt/rest/entity/rest.rb', line 111 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) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/rbbt/rest/entity/rest.rb', line 104 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) ⇒ Object
{{{ URLS
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rbbt/rest/entity/rest.rb', line 68 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 end if params.nil? if entity.respond_to? :entity_link_params params = entity.entity_link_params else params = {} end end params ||= entity.info if entity.respond_to? :info url = File.join('/', 'entity', Entity::REST.clean_element(type.to_s), entity) url << "?" << Misc.hash2GET_params(params) if params.any? url end |
.included(base) ⇒ Object
10 11 12 |
# File 'lib/rbbt/rest/entity/rest.rb', line 10 def self.included(base) REST_ENTITIES << base end |
.restore_element(elem) ⇒ Object
20 21 22 |
# File 'lib/rbbt/rest/entity/rest.rb', line 20 def self.restore_element(elem) CGI.unescape(CGI.unescape(elem.gsub('--', '/').gsub('o-o', '%'))) end |
Instance Method Details
#action_link(action, text = nil, options = {}) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rbbt/rest/entity/rest.rb', line 145 def action_link(action, text = nil, = {}) return self.collect{|e| e.link(action, text) } if Array === self klasses = self.klasses klasses << 'entity_action' attributes, link_params = ({:title => [action, self] * ": " }.merge()) attributes[:class] << klasses attributes[:href] = Entity::REST.entity_action_url(self, entity_type.to_s, action, link_params) if text.nil? or (String === text and text.empty?) text = self.respond_to?(:name)? self.name || self : self if text.nil? text = [text, action] * "→" end Misc.html_tag('a', text, attributes) end |
#base_type ⇒ Object
32 33 34 |
# File 'lib/rbbt/rest/entity/rest.rb', line 32 def base_type annotation_types.select{|mod| mod.include? Entity::REST }.first.to_s end |
#entity_link_params ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rbbt/rest/entity/rest.rb', line 24 def entity_link_params info = self.info.dup info.delete :format info.delete :annotation_types info.delete :annotated_array info end |
#entity_type ⇒ Object
43 44 45 |
# File 'lib/rbbt/rest/entity/rest.rb', line 43 def entity_type entity_type = self.respond_to?(:format) ? [base_type, format].compact.join(":") : base_type end |
#klasses ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rbbt/rest/entity/rest.rb', line 36 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 |
#link(text = nil, options = {}) ⇒ Object
{{{ LINKS
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rbbt/rest/entity/rest.rb', line 121 def link(text = nil, = {}) #return self.tap{|a| a.extend AnnotatedArray}.collect{|e| e.link(text, options) } if Array === self return self.collect{|e| e.link(text, ) } if Array === self klasses = self.klasses klasses << 'entity' attributes, link_params = () attributes[:class] << klasses attributes[:href] = Entity::REST.entity_url(self, entity_type.to_s, link_params) attributes["attr-entity_id"] = self.to_s begin text = self.respond_to?(:name)? self.name || self : self if text.nil? rescue text = self end attributes[:title] = text if attributes[:title].nil? Misc.html_tag('a', text, attributes) end |
#list_action_link(action, text = nil, id = nil, options = {}) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/rbbt/rest/entity/rest.rb', line 192 def list_action_link(action, text = nil, id = nil, = {}) text = [id, action] * "→" if text.nil? or (String === text and text.strip.empty?) id = [:id] || Misc.digest((self * "|").inspect) if id.nil? or (String === id and id.empty?) reuse = .delete(:reuse) reuse = .delete("reuse") if reuse.nil? reuse = true if reuse.nil? Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exists? Entity::List.list_file(entity_type.to_s, id, self) klasses = self.klasses klasses << 'entity_list_action' attributes, link_params = ({:title => [action, id] * ": " }.merge(), false) attributes[:class] = klasses attributes[:href] = Entity::REST.entity_list_action_url(id, entity_type.to_s, action, link_params) attributes[:title] = id if attributes[:title].nil? Misc.html_tag('a', text, attributes) end |
#list_link(text = nil, id = nil, options = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rbbt/rest/entity/rest.rb', line 163 def list_link(text = nil, id = nil, = {}) = Misc.add_defaults , :ensembl => USE_ENSEMBL ensembl = Misc. , :ensembl if ensembl and self.respond_to? :ensembl and self.format !~ /^Ensembl / return self.ensembl.compact.uniq.list_link(text, id, .merge({:ensembl => false})) end text = self.length if text.nil? or text == :length or (String === text and text.strip.empty?) id = [:id] || Misc.digest((self * "|").inspect) if id.nil? or (String === id and id.empty?) reuse = .delete(:reuse) reuse = .delete("reuse") if reuse.nil? reuse = true if reuse.nil? Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exists? Entity::List.list_file(entity_type.to_s, id, self) klasses = self.klasses klasses << 'entity_list' attributes, link_params = () attributes[:class] = klasses attributes[:href] = Entity::REST.entity_list_url(id, entity_type.to_s) attributes[:title] = id Misc.html_tag('a', text, attributes) end |
#process_link_options(options = {}, include_entity_params = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rbbt/rest/entity/rest.rb', line 47 def ( = {}, include_entity_params = true) attributes = {} link_params = include_entity_params ? entity_link_params : {} %w(class style title).each do |at| attributes[at.to_sym] = .delete(at.to_sym) || .delete(at.to_s) || nil end attributes[:class] = attributes[:class].split(" ") if String === attributes[:class] attributes[:class] = [] if attributes[:class].nil? link_params = link_params.merge() [attributes, link_params] end |