Class: Hashtags::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/hashtags/resource.rb

Instance Attribute Summary

Attributes inherited from Base

#str

Class Method Summary collapse

Methods inherited from Base

descendants, json_for_query, json_regexp, match_template, path, resource_classes, strategy, to_hashtag, #to_hashtag, to_markup, #to_markup, user_classes, values, variable_classes

Class Method Details

.cache_keyObject



19
20
21
# File 'lib/hashtags/resource.rb', line 19

def self.cache_key
  resource_class.cache_key
end

.find_by_resource_type(resource_type) ⇒ Object



11
12
13
# File 'lib/hashtags/resource.rb', line 11

def self.find_by_resource_type(resource_type)
  descendants.detect{ |cls| cls.resource_name.to_s == resource_type.to_s }
end

.help_valuesObject



44
45
46
# File 'lib/hashtags/resource.rb', line 44

def self.help_values
  [resource_name]
end

.match_indexObject



55
56
57
# File 'lib/hashtags/resource.rb', line 55

def self.match_index
  2
end

.match_regexpObject


JS



51
52
53
# File 'lib/hashtags/resource.rb', line 51

def self.match_regexp
  /(#{Regexp.escape(trigger)}#{resource_name}\:)(\w{1,})\z/
end

.regexpObject



40
41
42
# File 'lib/hashtags/resource.rb', line 40

def self.regexp
  /#{Regexp.escape(trigger)}#{resource_name}:(.+?)\((.+?)\b\)/i
end

.replaceObject



59
60
61
# File 'lib/hashtags/resource.rb', line 59

def self.replace
  "#{trigger}#{resource_name}:{{ #{tag_attribute} }}({{ id }})"
end

.resource_classObject

implement as resource class in your application

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/hashtags/resource.rb', line 7

def self.resource_class
  raise NotImplementedError
end

.resource_nameObject



15
16
17
# File 'lib/hashtags/resource.rb', line 15

def self.resource_name
  resource_class.to_s.demodulize.underscore
end

.result_attributeObject

the tags will be replaced by this attribute (for example :link_to)

Raises:

  • (NotImplemented)


36
37
38
# File 'lib/hashtags/resource.rb', line 36

def self.result_attribute
  raise NotImplemented
end

.tag_attributeObject

name of attribute to be used in the tag #resource_name:<tag_attribute>(id) (for example :to_s)

Raises:

  • (NotImplemented)


30
31
32
# File 'lib/hashtags/resource.rb', line 30

def self.tag_attribute
  raise NotImplemented
end

.templateObject



63
64
65
# File 'lib/hashtags/resource.rb', line 63

def self.template
  "{{ #{tag_attribute} }}"
end

.triggerObject



23
24
25
# File 'lib/hashtags/resource.rb', line 23

def self.trigger
  '#'
end