Class: Cohortly::TagConfig
- Inherits:
-
Object
- Object
- Cohortly::TagConfig
- Includes:
- Singleton
- Defined in:
- lib/cohortly/tag_config.rb
Defined Under Namespace
Classes: Controller, Tag
Instance Attribute Summary collapse
-
#_groups ⇒ Object
Returns the value of attribute _groups.
-
#_tags ⇒ Object
Returns the value of attribute _tags.
-
#lookup_table ⇒ Object
Returns the value of attribute lookup_table.
Class Method Summary collapse
- .all_groups ⇒ Object
- .all_tags ⇒ Object
- .draw_tags(&block) ⇒ Object
- .tags_for(controller, action = :_all) ⇒ Object
Instance Method Summary collapse
- #compile! ⇒ Object
- #groups(*args) ⇒ Object
- #tag(tag_name, &block) ⇒ Object
- #tags(*args, &block) ⇒ Object
- #tags_for(controller, action = :_all) ⇒ Object
Instance Attribute Details
#_groups ⇒ Object
Returns the value of attribute _groups.
5 6 7 |
# File 'lib/cohortly/tag_config.rb', line 5 def _groups @_groups end |
#_tags ⇒ Object
Returns the value of attribute _tags.
5 6 7 |
# File 'lib/cohortly/tag_config.rb', line 5 def end |
#lookup_table ⇒ Object
Returns the value of attribute lookup_table.
5 6 7 |
# File 'lib/cohortly/tag_config.rb', line 5 def lookup_table @lookup_table end |
Class Method Details
.all_groups ⇒ Object
62 63 64 |
# File 'lib/cohortly/tag_config.rb', line 62 def self.all_groups instance._groups.sort end |
.all_tags ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/cohortly/tag_config.rb', line 54 def self. if instance. instance..collect {|x| x._name.to_s } else [] end end |
.draw_tags(&block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/cohortly/tag_config.rb', line 6 def self.(&block) instance. = [] instance._groups = [] instance.lookup_table = {} instance.instance_eval(&block) instance.compile! instance end |
.tags_for(controller, action = :_all) ⇒ Object
49 50 51 52 |
# File 'lib/cohortly/tag_config.rb', line 49 def self.(controller, action = :_all) return [] if controller.nil? instance.(controller, action) end |
Instance Method Details
#compile! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cohortly/tag_config.rb', line 27 def compile! self..each do |tag| tag._controllers.each do |cont| lookup_table[cont._name] ||= {} cont._acts.each do |a| lookup_table[cont._name][a] ||= [] tag_names = lookup_table[cont._name][a] << tag._name lookup_table[cont._name][a] = tag_names.uniq end end end end |
#groups(*args) ⇒ Object
23 24 25 |
# File 'lib/cohortly/tag_config.rb', line 23 def groups(*args) self._groups = *args.collect(&:to_s) end |
#tag(tag_name, &block) ⇒ Object
15 16 17 |
# File 'lib/cohortly/tag_config.rb', line 15 def tag(tag_name, &block) self. << Tag.new(tag_name, &block) end |
#tags(*args, &block) ⇒ Object
19 20 21 |
# File 'lib/cohortly/tag_config.rb', line 19 def (*args, &block) args.each {|x| tag(x, &block) } end |
#tags_for(controller, action = :_all) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/cohortly/tag_config.rb', line 40 def (controller, action = :_all) res = [] if lookup_table[controller.to_sym] res += lookup_table[controller.to_sym][action.to_sym] || [] res += lookup_table[controller.to_sym][:_all] || [] end res.uniq.collect &:to_s end |