Class: Watobo::Scope
- Inherits:
-
Object
- Object
- Watobo::Scope
- Defined in:
- lib/watobo/core/scope.rb
Overview
:nodoc: all
Class Method Summary collapse
- .add(site) ⇒ Object
- .each(&block) ⇒ Object
- .exist? ⇒ Boolean
- .match_chat?(chat) ⇒ Boolean
- .match_site?(site) ⇒ Boolean
- .reset ⇒ Object
- .set(scope) ⇒ Object
- .to_s ⇒ Object
- .to_yaml ⇒ Object
Class Method Details
.add(site) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/watobo/core/scope.rb', line 72 def self.add(site) scope_details = { :site => site, :enabled => true, :root_path => '', :excluded_paths => [], } @scope[site] = scope_details return true end |
.each(&block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/watobo/core/scope.rb', line 29 def self.each(&block) if block_given? @scope.each do |site, scope| yield [ site, scope] end end end |
.exist? ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/watobo/core/scope.rb', line 17 def self.exist? return false if @scope.empty? @scope.each_value do |s| return true if s[:enabled] == true end return false end |
.match_chat?(chat) ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/watobo/core/scope.rb', line 42 def self.match_chat?(chat) #puts @scope.to_yaml return true if @scope.empty? site = chat.request.site if @scope.has_key? site path = chat.request.path url = chat.request.url.to_s scope = @scope[site] if scope.has_key? :root_path unless scope[:root_path].empty? return false unless path =~ /^(\/)?#{scope[:root_path]}/i end end return true unless scope.has_key? :excluded_paths scope[:excluded_paths].each do |p| # puts "#{url} - #{p}" return false if url =~ /#{p}/ end return true end return false end |
.match_site?(site) ⇒ Boolean
37 38 39 40 |
# File 'lib/watobo/core/scope.rb', line 37 def self.match_site?(site) return true if @scope.empty? @scope.has_key? site end |
.reset ⇒ Object
25 26 27 |
# File 'lib/watobo/core/scope.rb', line 25 def self.reset @scope = {} end |
.set(scope) ⇒ Object
13 14 15 |
# File 'lib/watobo/core/scope.rb', line 13 def self.set(scope) @scope = scope end |
.to_s ⇒ Object
5 6 7 |
# File 'lib/watobo/core/scope.rb', line 5 def self.to_s @scope.to_yaml end |
.to_yaml ⇒ Object
9 10 11 |
# File 'lib/watobo/core/scope.rb', line 9 def self.to_yaml @scope.to_yaml end |