class Lolita::SystemConfiguration::Base

Attributes

ability_class[W]
authentication[RW]
authorization[RW]
controllers[R]
default_locale[W]
default_route[RW]
mappings[RW]
modules[R]
policy_class[W]
resources[R]
routes[R]
scope[R]
tinymce_configuration_set[W]
user_classes[RW]

Public Class Methods

new(scope) click to toggle source
# File lib/lolita/system_configuration/base.rb, line 8
def initialize(scope)
  @scope=scope
  @mappings={}
  @resources={}
  @default_module=nil
  @user_classes=[]
  @modules=[]
  @routes={}
  @controllers={}
end

Public Instance Methods

ability_class() click to toggle source
# File lib/lolita/system_configuration/base.rb, line 35
def ability_class
  @ability_class || (::Ability rescue nil) || raise("No ability class found.")
end
add_mapping(resource,options={}) click to toggle source
# File lib/lolita/system_configuration/base.rb, line 115
def add_mapping(resource,options={})
  mapping = Lolita::Mapping.new(resource, options)
  self.mappings[mapping.name] = mapping
  mapping
end
add_module(module_container, options={}) click to toggle source

Add new module to Lolita Accpted options

  • controller - not in use

  • nested - is route stands itsefl or is used in combination with resource

  • route - Symbol of route name or lambad, that return route name based on resource.

Route name is used to call method lolita_ in Mapper class, and that should draw route.

  • :name - name of module, underscored symbol. Used to draw default route, by default always

lolita_rest is called, but if route with resource name is found, than by default this route will be drawn. Like lolita_for :posts, can go to different controller than rest and do other things.

  • :path - some file that will be included. Deprecated will be removed

Example

Lolita.add_module Lolita::Posts, :route=>:post, :name=>:post
lolita_for :posts #=> create url whatever is defined in lolita_post method, and goes to :controller=>"lolita/posts"
Lolita.add_module Lolita::FileUpload, :route=>lambda{|resource| resource.lolita.tabs.by_type(:file) ? :file_upload : nil}
lolita_for :users #=> creat default rest urls and also call method lolita_file_upload if user lolita define :file tab.

To add route for public interface that goes to added module, than use

Lolita.add_module Post, :name=>:posts

And then when in routes.rb will be defined lolita_for(:posts) it will call method lolita_posts_route and that method should define resource.

Example

# require this in your gem or lib
module ActionDispatch::Routing
   class Mapper
     protected
     def lolita_posts_route mapping, controllers
       resources mapping.plural,:only=>[:index,:new,:create],
         :controller=>controllers[:posts],:module=>mapping.module
     end
   end
 end

You open Mapper class and add your method that call resources or match or other method that define route For common route for all lolita resources your method should look like this

Example

def lolita_files_route 
   mapping=Lolita.add_mapping(:files,:class_name=>"Lolita::Multimedia::File",:module=>"file_upload")
   scope :module=>mapping.module do
       resources mapping.name
   end
end
# File lib/lolita/system_configuration/base.rb, line 160
def add_module module_container, options={}
  raise ArgumentError, "Can't add module without module container!" unless module_container
  options.assert_valid_keys(:controller,:route,:model,:path,:name,:nested)
  name=options[:name]||module_container.to_s.to_sym
  self.modules<<module_container

  if options.has_key?(:route)
    self.routes[name]=[options.has_key?(:nested) ? options[:nested] : true,options[:route]]
  end
  self.controllers[name]=options[:controller] if options.has_key?(:controller)

  if options[:path]
    require File.join(options[:path],name.to_s)
  end
end
application() { |application| ... } click to toggle source
# File lib/lolita/system_configuration/base.rb, line 19
def application &block
  @application ||= Lolita::SystemConfiguration::Application.new
  if block_given?
    yield @application
  end
  @application
end
common_routes(klasses) click to toggle source

Find all routes that is needed for defined classes And return only one for each different route.

# File lib/lolita/system_configuration/base.rb, line 102
def common_routes(klasses)
  @routes.map{|name,route|
    unless route.first
      klasses.map{|klass| route.last.respond_to?(:call) ? route.last.call(klass) : route.last}
    end
  }.flatten.compact.uniq
end
conditional_routes(klass=nil) click to toggle source

Call (with call) to route klass And return all names of routes that are needed for resource. When with add_module routes are defined like

Lolita.add_module MyModule, :route=>:my_module

then this will be passed to the method that creates routes, but when Proc is passed to :route then this Proc should return name of route or nil. These names then are used for methods like lolita_[route_name]_route that should be required somewhere in you module.

# File lib/lolita/system_configuration/base.rb, line 88
def conditional_routes(klass=nil)
  @routes.map{|name,route|
    if route.first
      if route.last.respond_to?(:call)
        route.last.call(klass)
      else
        route.last
      end
    end
  }.compact
end
default_locale() click to toggle source

Return default locale. First looks for defined default locale for Lolita, when not found than take first of defined locales for Lolita, if there no defined locales for Lolita, than look for I18n and take default locale from there or if there is no I18n than take :en

# File lib/lolita/system_configuration/base.rb, line 75
def default_locale
  @default_locale || self.locales.first || (defined?(::I18n) ? ::I18n.default_locale : :en)
end
locale() click to toggle source
# File lib/lolita/system_configuration/base.rb, line 56
def locale()
  @locale || default_locale
end
locale=(given_locale) click to toggle source
# File lib/lolita/system_configuration/base.rb, line 60
def locale=given_locale
  @locale=if locales.include?(given_locale.to_s.to_sym)
    given_locale.to_s.to_sym
  else
    Lolita.default_locale
  end
  if defined?(::I18n)
    ::I18n.locale = @locale
  end
  @locale
end
locales() click to toggle source
# File lib/lolita/system_configuration/base.rb, line 52
def locales
  @locales || []
end
locales=(value) click to toggle source
# File lib/lolita/system_configuration/base.rb, line 44
def locales=(value)
  unless value.is_a?(Array)
    @locales=[value]
  else
    @locales=value
  end
end
navigation() click to toggle source
policy_class() click to toggle source

policy class for Pundit

# File lib/lolita/system_configuration/base.rb, line 40
def policy_class
  @policy_class || (::LolitaPolicy rescue nil) || raise("No policy class found.")
end
tinymce_configuration_set() click to toggle source

Should return one of defined configuration set names from tinymce.yml

# File lib/lolita/system_configuration/base.rb, line 177
def tinymce_configuration_set
  @tinymce_configuration_set || :default
end
use(module_name) click to toggle source

Include module in Lolita, don't know why i need this

# File lib/lolita/system_configuration/base.rb, line 111
def use(module_name)
  Lolita.send(:include,module_name)
end