Sha256: 2def5f9f3ad9e6559275197a247ad91bcedbdcf187ca07f4d413e52655b9eb37

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'compass-rails'
require 'bootstrap-sass'
require 'jquery-rails'
require 'rest_client'
require 'stop_ie'
require 'tusur_cdn'

module TusurHeader
  class Engine < ::Rails::Engine
    def self.sites
      @sites ||= YAML.load_file(File.expand_path('../../../config/sites.yml', __FILE__))
    end

    config.after_initialize do
      begin
        Settings.define 'profile.url', :require => true

        Settings.resolve!
      rescue => e
        puts "WARNING! #{e.message}"
      end
    end

    config.to_prepare do
      ActiveRecord::Base.class_eval do
        def self.has_remote_profile
          define_method :remote_profile do |kind|
            response = RestClient.get("#{Settings['profile.url']}/api/#{kind}", :params => { :uid => self.uid }, :content_type => :json, :accept => :json)
            JSON.parse(response)[kind]
          end

          define_method :get_notifications do
            @get_notification_count ||= remote_profile('notifications').to_i
          end

          define_method :get_menu do
            @get_menu ||= (remote_profile('menu') || [])
          end
        end
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tusur_header-0.2.10 lib/tusur_header/engine.rb
tusur_header-0.2.9 lib/tusur_header/engine.rb
tusur_header-0.2.8 lib/tusur_header/engine.rb
tusur_header-0.2.7 lib/tusur_header/engine.rb