Module: MultiSite::ScopedModel::ScopedClassMethods
- Defined in:
- lib/multi_site/scoped_model.rb
Instance Method Summary collapse
- #current_site ⇒ Object
- #current_site! ⇒ Object
- #find_initial_without_site(options) ⇒ Object
-
#find_without_site(*args) ⇒ Object
this only works with :all and :first and should only be used in odd cases like migration.
- #is_shareable? ⇒ Boolean
- #is_site_scoped? ⇒ Boolean
- #paginate_with_site(options = {}) ⇒ Object
- #plural_symbol_for_class ⇒ Object
- #site_scope_condition ⇒ Object
- #sites? ⇒ Boolean
Instance Method Details
#current_site ⇒ Object
96 97 98 |
# File 'lib/multi_site/scoped_model.rb', line 96 def current_site Page.current_site end |
#current_site! ⇒ Object
91 92 93 94 |
# File 'lib/multi_site/scoped_model.rb', line 91 def current_site! raise(ActiveRecord::SiteNotFound, "#{self} is site-scoped but current_site is #{self.current_site.inspect}", caller) if sites? && !self.current_site && !self.is_shareable? self.current_site end |
#find_initial_without_site(options) ⇒ Object
82 83 84 85 |
# File 'lib/multi_site/scoped_model.rb', line 82 def find_initial_without_site() .update(:limit => 1) all_without_site().first end |
#find_without_site(*args) ⇒ Object
this only works with :all and :first and should only be used in odd cases like migration.
72 73 74 75 76 77 78 79 80 |
# File 'lib/multi_site/scoped_model.rb', line 72 def find_without_site(*args) = args. #set_readonly_option!(options) case args.first when :first then find_initial_without_site() # defined here when :all then all_without_site() # already defined by the alias chain end end |
#is_shareable? ⇒ Boolean
119 120 121 |
# File 'lib/multi_site/scoped_model.rb', line 119 def is_shareable? !!self.shareable end |
#is_site_scoped? ⇒ Boolean
115 116 117 |
# File 'lib/multi_site/scoped_model.rb', line 115 def is_site_scoped? true end |
#paginate_with_site(options = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/multi_site/scoped_model.rb', line 54 def paginate_with_site(={}) return paginate_without_site() unless sites? where(site_scope_condition) do paginate_without_site() end end |
#plural_symbol_for_class ⇒ Object
111 112 113 |
# File 'lib/multi_site/scoped_model.rb', line 111 def plural_symbol_for_class self.to_s.pluralize.underscore.intern end |
#site_scope_condition ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/multi_site/scoped_model.rb', line 100 def site_scope_condition if self.shareable condition = "" condition << "#{self.table_name}.site_id = #{self.current_site.id} OR " if self.current_site condition << "#{self.table_name}.site_id IS NULL" else condition = "#{self.table_name}.site_id = #{self.current_site!.id}" end condition end |
#sites? ⇒ Boolean
87 88 89 |
# File 'lib/multi_site/scoped_model.rb', line 87 def sites? Site.table_exists? && Site.several? end |