Sha256: eba2c58febe7879461348bc1e39d8269bf3f1b51c2063daca5aea0e663d12581

Contents?: true

Size: 1.48 KB

Versions: 40

Compression:

Stored size: 1.48 KB

Contents

module Spud::BelongsToApp
	extend ActiveSupport::Concern
	included do
		extend ClassMethods
	end
    # class Config
    # 	attr_reader :page_application
    # 	attr_reader :page_thumbnail
    # 	def initialize(app,thumb)
    # 		@page_application = app
    # 		@page_thumbnail = thumb
    # 	end
    # end
	module ClassMethods
		def belongs_to_spud_app(name=nil)
			
			Spud::Core.admin_applications.each do |app|
					if app[:name].parameterize.underscore.to_sym == name
						@page_application = app
						break
					end
				end
			self.class_eval do

				before_filter { |controller|
					@page_thumbnail = self.class.page_application[:thumbnail]
					@page_name = self.class.page_application[:name]

					if current_user.super_admin == false
						permission = current_user_permissions.select{|perm| perm.name == @page_name}
						if permission.blank?
							flash[:error] = "You do not have access to this area."
							redirect_to spud_admin_root_url and return
						end
					end

					if controller.action_name == 'new' || controller.action_name == 'create'
						@page_name = "New #{@page_name.singularize}"
					elsif controller.action_name == 'edit' || controller.action_name == 'update'
							@page_name = "Edit #{@page_name.singularize}"
					elsif controller.action_name == 'show'
						@page_name = "Show #{@page_name.singularize}"
					end

				}
					
			end

		end
		def page_application
		      @page_application || self.superclass.instance_variable_get('@page_application')
	    end
	end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
spud_core-0.8.6 lib/spud_core/belongs_to_app.rb
spud_core-0.8.5 lib/spud_core/belongs_to_app.rb
spud_core-0.8.4 lib/spud_core/belongs_to_app.rb
spud_core-0.8.2 lib/spud_core/belongs_to_app.rb
spud_core-0.8.1 lib/spud_core/belongs_to_app.rb
spud_core-0.8.0 lib/spud_core/belongs_to_app.rb
spud_core-0.7.5 lib/spud_core/belongs_to_app.rb
spud_core-0.7.4 lib/spud_core/belongs_to_app.rb
spud_core-0.7.2 lib/spud_core/belongs_to_app.rb
spud_core-0.7.1 lib/spud_core/belongs_to_app.rb
spud_core-0.7.0 lib/spud_core/belongs_to_app.rb
spud_core-0.6.4 lib/spud_core/belongs_to_app.rb
spud_core-0.6.2 lib/spud_core/belongs_to_app.rb
spud_core-0.5.6 lib/spud_core/belongs_to_app.rb
spud_core-0.5.5 lib/spud_core/belongs_to_app.rb
spud_core-0.5.2 lib/spud_core/belongs_to_app.rb
spud_core-0.5.1 lib/spud_core/belongs_to_app.rb
spud_core-0.5.0 lib/spud_core/belongs_to_app.rb
spud_core-0.4.0 lib/spud_core/belongs_to_app.rb
spud_admin-0.2.0 lib/spud_admin/belongs_to_app.rb