Class: Intro::Tour
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Intro::Tour
- Defined in:
- app/models/intro/tour.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear_cache ⇒ Object
- #expired? ⇒ Boolean
- #expose_attributes ⇒ Object
- #format_attributes ⇒ Object
- #simple_route ⇒ Object
- #simple_route_changed? ⇒ Boolean
- #strict_route? ⇒ Boolean
- #update_route ⇒ Object
Class Method Details
.extract_route(url) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/intro/tour.rb', line 43 def extract_route(url) url = "/#{url}" if url !~ /^((https?:\/\/)|(\/))/i uri = URI(url) { source: recognize_path(uri.path), query: uri.query } rescue {} end |
Instance Method Details
#clear_cache ⇒ Object
98 99 100 101 102 |
# File 'app/models/intro/tour.rb', line 98 def clear_cache if destroyed? || (previous_changes.keys & %w[controller_path action_name published]).any? Intro.cache.delete(controller_path, action_name) end end |
#expired? ⇒ Boolean
38 39 40 |
# File 'app/models/intro/tour.rb', line 38 def expired? !!expired_at && expired_at < Time.now end |
#expose_attributes ⇒ Object
20 21 22 |
# File 'app/models/intro/tour.rb', line 20 def expose_attributes as_json(only: %i[id ident controller_path action_name options]).with_indifferent_access end |
#format_attributes ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/models/intro/tour.rb', line 74 def format_attributes %i[ident controller_path action_name].each do |attribute| strip_attribute = send(attribute).try(:strip) send("#{attribute}=", strip_attribute) end self. = JSON.parse() rescue {} unless .is_a?(Hash) self.route = JSON.parse(route) rescue {} unless route.is_a?(Hash) end |
#simple_route ⇒ Object
24 25 26 |
# File 'app/models/intro/tour.rb', line 24 def simple_route route[:simple] rescue nil end |
#simple_route_changed? ⇒ Boolean
28 29 30 31 32 |
# File 'app/models/intro/tour.rb', line 28 def simple_route_changed? return false unless route_changed? simple_route != route_was[:simple] rescue false end |
#strict_route? ⇒ Boolean
34 35 36 |
# File 'app/models/intro/tour.rb', line 34 def strict_route? route[:strict] rescue false end |
#update_route ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/intro/tour.rb', line 84 def update_route if simple_route.present? && simple_route_changed? route = self.class.extract_route(simple_route) source = route[:source] || {} self.controller_path = source[:controller].to_s if self.controller_path.blank? self.action_name = source[:action].to_s if self.action_name.blank? self.route.reverse_merge!(route) end self.route[:strict] = %w[1 true].include?(self.route[:strict].to_s) self.route end |