Sha256: ea00eebd9f443ea7b84a98353c263ae83c7a29a435cc89f6f6e7e38a6b0b2129

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'rest_client'
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

6 entries across 6 versions & 1 rubygems

Version Path
tusur_header-0.2.17 lib/tusur_header/engine.rb
tusur_header-0.2.15 lib/tusur_header/engine.rb
tusur_header-0.2.14 lib/tusur_header/engine.rb
tusur_header-0.2.13 lib/tusur_header/engine.rb
tusur_header-0.2.12 lib/tusur_header/engine.rb
tusur_header-0.2.11 lib/tusur_header/engine.rb