Permalink
Browse files

Renamed gem. Removed unused and refactored all code.

  • Loading branch information...
Dmitriy Vorotilin
Dmitriy Vorotilin committed Mar 21, 2012
1 parent 16514bc commit 37130226503c5916de4995b42c62bebd06c568d4
View
@@ -1,4 +1,3 @@
source 'https://rubygems.org'
-# Specify your gem's dependencies in ultimate-log-silencer.gemspec
gemspec
View
@@ -1,44 +1,27 @@
-# Ultimate Log Silencer
+# Quiet assets
-Ultimate Log Silencer can clear development logs and mutes assets pipeline log-messages, sort of:
+Quiet assets turn off assets pipeline log, kind of:
-```log
-Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-02-13 13:24:04 +0400
-Served asset /application.js - 304 Not Modified (8ms)
-```
+ Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-02-13 13:24:04 +0400
+ Served asset /application.js - 304 Not Modified (8ms)
-Support Ruby on Rails 3.1, 3.2.
+Support Ruby on Rails ~> 3.1
## Installation
Add this line to your application's Gemfile:
- gem 'ultimate-log-silencer'
+ gem 'quiet_assets'
And then execute:
$ bundle
-Or install it yourself as:
-
- $ gem install ultimate-log-silencer
-
## Usage
-Nothing more, but you can change some options:
-
-```ruby
-# Assign null-logger for assets.
-config.ultimate_log_silencer.assets_logger_off = false
-# Off messages from Rack by request path.
-config.ultimate_log_silencer.rack_logger_assets_off = true
-# RegExp for detect request to assets.
-config.ultimate_log_silencer.assets_path_regexp = /^\/assets\//
-# Allow remove logs exceeded max_log_size.
-config.ultimate_log_silencer.clear_logs = false
-# Max allowed log size.
-config.ultimate_log_silencer.max_log_size = 2.megabytes
-```
+Nothing to do, but if you want to temporarily turn on back assets' log just write:
+
+ config.quite_assets = true
## License
@@ -47,4 +30,4 @@ Dual licensed under the MIT and GPL licenses:
+ http://www.opensource.org/licenses/mit-license.php
+ http://www.gnu.org/licenses/gpl.html
-Copyright © 2011-2012 Dmitry KODer Karpunun / Evrone.com
+Copyright © 2011-2012 Dmitry [KODerFunk](https://github.com/KODerFunk) Karpunun, Dmitry [route](https://github.com/route) Vorotilin / [Evrone.com](http://evrone.com)
View
@@ -0,0 +1,29 @@
+require "quiet_assets/version"
+
+module QuietAssets
+ class Engine < ::Rails::Engine
+ # Set as true but user can override it
+ config.quiet_assets = true
+
+ initializer "quiet_assets", :after => "sprockets.environment" do |app|
+ if app.config.quiet_assets == true
+ app.config.assets.logger = false
+
+ # Just create an alias for call in middleware
+ Rails::Rack::Logger.class_eval do
+ def call_with_quiet_assets(env)
+ old_logger_level, level = Rails.logger.level, Logger::ERROR
+ # Increase log level because of messages that have a low level should not be displayed
+ Rails.logger.level = level if env['PATH_INFO'].index("/assets/") == 0
+ call_without_quiet_assets(env)
+ ensure
+ # Return back
+ Rails.logger.level = old_logger_level
+ end
+
+ alias_method_chain :call, :quiet_assets
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module QuietAssets
+ VERSION = "1.0.0"
+end
@@ -1,10 +0,0 @@
-require "ultimate-log-silencer/version"
-require "ultimate-log-silencer/engine"
-
-module Ultimate
- module Log
- module Silencer
-
- end
- end
-end
@@ -1,12 +0,0 @@
-if Rails.application.config.ultimate_log_silencer.clear_logs
- include ActionView::Helpers::NumberHelper
- logs = File.join(Rails.root, 'log', '*.log')
- Dir[logs].each do |log|
- file_size = File.size? log
- if file_size.to_i > Rails.application.config.ultimate_log_silencer.max_log_size
- $stdout.puts "=> Ultimate Log Silencer: clearing #{log.gsub Rails.root.to_s, ''} (#{number_to_human_size file_size})"
- f = File.open log, "w"
- f.close
- end
- end
-end
@@ -1,34 +0,0 @@
-module Ultimate
- module Log::Silencer
-
- class Configuration
- require "active_support/core_ext/numeric/bytes"
-
- # Assign null-logger for assets.
- attr_accessor :assets_logger_off
-
- # Off messages from Rack by request path.
- attr_accessor :rack_logger_assets_off
-
- # RegExp for detect request to assets.
- attr_accessor :assets_path_regexp
-
- # Allow remove logs exceeded max_log_size.
- attr_accessor :clear_logs
-
- # Max allowed log size.
- attr_accessor :max_log_size
-
- def initialize
- # Set configuration defaults.
- @assets_logger_off = false
- @rack_logger_assets_off = true
- @assets_path_regexp = /^\/assets\//
- @clear_logs = false
- @max_log_size = 2.megabytes
- end
-
- end
-
- end
-end
@@ -1,15 +0,0 @@
-require "ultimate-log-silencer/configuration"
-
-module Ultimate
- module Log
- module Silencer
- class Engine < ::Rails::Engine
- config.ultimate_log_silencer = Ultimate::Log::Silencer::Configuration.new
- initializer "ultimate-log-sillencer.quiet_assets", :after => "sprockets.environment" do
- require "ultimate-log-silencer/clear_logs"
- require "ultimate-log-silencer/quiet_assets"
- end
- end
- end
- end
-end
@@ -1,16 +0,0 @@
-if Rails.application.config.ultimate_log_silencer.assets_logger_off
- Rails.application.assets.logger = Logger.new(RUBY_PLATFORM =~ /(win|w)32$/ ? "NUL" : "/dev/null")
-end
-
-if Rails.application.config.ultimate_log_silencer.rack_logger_assets_off
- Rails::Rack::Logger.class_eval do
- def call_with_quiet_assets(env)
- previous_level = Rails.logger.level
- Rails.logger.level = Logger::ERROR if Rails.application.config.ultimate_log_silencer.assets_path_regexp =~ env['PATH_INFO']
- call_without_quiet_assets(env).tap do
- Rails.logger.level = previous_level
- end
- end
- alias_method_chain :call, :quiet_assets
- end
-end
@@ -1,7 +0,0 @@
-module Ultimate
- module Log
- module Silencer
- VERSION = "0.2.1"
- end
- end
-end
View
@@ -0,0 +1,16 @@
+require File.expand_path('../lib/quiet_assets/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.name = "quiet_assets"
+ gem.version = QuietAssets::VERSION
+ gem.authors = ["Dmitry Karpunin", "Dmitry Vorotilin"]
+ gem.email = ["koderfunk@gmail.com", "d.vorotilin@gmail.com"]
+ gem.homepage = "http://github.com/evrone/quiet_assets"
+ gem.description = "Quiet assets turn off rails assests log."
+ gem.summary = "Turn off rails assests log."
+
+ gem.files = `git ls-files`.split("\n")
+ gem.require_paths = ["lib"]
+
+ gem.add_dependency "rails", "~> 3.1"
+end
@@ -1,20 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/ultimate-log-silencer/version', __FILE__)
-
-Gem::Specification.new do |gem|
- gem.name = "ultimate-log-silencer"
- gem.version = Ultimate::Log::Silencer::VERSION
- gem.authors = ["Dmitry KODer Karpunin"]
- gem.email = ["koderfunk@gmail.com"]
- gem.homepage = "http://github.com/evrone/ultimate-log-silencer"
- gem.description = %q{Ultimate Log Silencer mutes assets pipeline log-messages.}
- gem.summary = %q{Ultimate Log Silencer mutes assets pipeline log-messages.}
-
- gem.add_dependency "rails", "~> 3.1"
-
- gem.files = `git ls-files`.split("\n")
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- gem.require_paths = ["lib"]
-
-end

0 comments on commit 3713022

Please sign in to comment.