Class: Lipsiadmin::AccessControl::ProjectModule

Inherits:
Object
  • Object
show all
Includes:
ActionController::UrlWriter, Helper
Defined in:
lib/access_control/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#recognize_path

Constructor Details

#initialize(name, path = nil, options = {}) {|_self| ... } ⇒ ProjectModule

:nodoc:

Yields:

  • (_self)

Yield Parameters:



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/access_control/base.rb', line 140

def initialize(name, path=nil, options={}, &block)#:nodoc:
  @name = name
  @options = options
  @allowed = []
  @menus   = []
  if path
    @url      = recognize_path(path)
    @allowed << { :controller => @url[:controller] }
  end
  yield self
end

Instance Attribute Details

Returns the value of attribute menus.



138
139
140
# File 'lib/access_control/base.rb', line 138

def menus
  @menus
end

#nameObject (readonly)

Returns the value of attribute name.



138
139
140
# File 'lib/access_control/base.rb', line 138

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



138
139
140
# File 'lib/access_control/base.rb', line 138

def url
  @url
end

Instance Method Details

#allowedObject

Return allowed controllers



158
159
160
161
# File 'lib/access_control/base.rb', line 158

def allowed
  @menus.each { |m| @allowed.concat(m.allowed) }
  @allowed.uniq
end

#configObject

Return ExtJs Config for this project module



174
175
176
177
178
179
# File 'lib/access_control/base.rb', line 174

def config
  options = @options.merge(:text => human_name)
  options.merge!(:menu => @menus.collect(&:config)) if @menus.size > 0
  options.merge!(:handler =>  "function(){ Backend.app.load('#{url_for(@url.merge(:only_path => true))}') }".to_l) if @url
  options
end

#human_nameObject

Return the original name or try to translate or humanize the symbol



164
165
166
# File 'lib/access_control/base.rb', line 164

def human_name
  @name.is_a?(Symbol) ? I18n.t("backend.menus.#{@name}", :default => @name.to_s.humanize) : @name
end

Build a new menu and automaitcally add the action on the allowed actions.



153
154
155
# File 'lib/access_control/base.rb', line 153

def menu(name, path=nil, options={}, &block)
  @menus << Menu.new(name, path, options, &block)
end

#uidObject

Return a unique id for the given project module



169
170
171
# File 'lib/access_control/base.rb', line 169

def uid
  @name.to_s.downcase.gsub(/[^a-z0-9]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '')
end