Skip to content

Commit 8e04272

Browse files
committed
style fixes, dropping old-style hash
1 parent 8aace36 commit 8e04272

File tree

69 files changed

+695
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+695
-726
lines changed

Gemfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source "http://rubygems.org"
1+
source 'http://rubygems.org'
22

33
# Declare your gem's dependencies in lit.gemspec.
44
# Bundler will treat runtime dependencies like base dependencies, and
@@ -28,9 +28,9 @@ group :test do
2828
gem 'simple_form'
2929
gem 'ransack'
3030
gem 'kaminari'
31-
gem 'fakeweb', "~> 1.3", :require=>false
32-
gem "test_declarative", :require => false
33-
gem 'mocha', :require => false
31+
gem 'fakeweb', '~> 1.3', require: false
32+
gem 'test_declarative', require: false
33+
gem 'mocha', require: false
3434
end
3535

3636
group :development, :test do

Rakefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rescue LoadError
1313
RDoc::Task = Rake::RDocTask
1414
end
1515

16-
1716
RDoc::Task.new(:rdoc) do |rdoc|
1817
rdoc.rdoc_dir = 'rdoc'
1918
rdoc.title = 'Lit'
@@ -22,7 +21,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
2221
rdoc.rdoc_files.include('lib/**/*.rb')
2322
end
2423

25-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
2625
load 'rails/tasks/engine.rake'
2726

2827
Bundler::GemHelper.install_tasks
@@ -36,5 +35,3 @@ Rake::TestTask.new(:test) do |t|
3635
t.pattern = 'test/**/*_test.rb'
3736
t.verbose = false
3837
end
39-
40-

app/controllers/lit/api/v1/base_controller.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ class BaseController < ActionController::Base
66
respond_to :json
77
before_filter :authenticate_requests!
88

9-
109
private
11-
def authenticate_requests!
12-
authenticate_or_request_with_http_token do |token, options|
13-
Lit.api_key == token
14-
end
10+
11+
def authenticate_requests!
12+
authenticate_or_request_with_http_token do |token, _options|
13+
Lit.api_key == token
1514
end
15+
end
1616
end
1717
end
1818
end

app/controllers/lit/api/v1/locales_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
require_dependency "lit/api/v1/base_controller"
1+
require_dependency 'lit/api/v1/base_controller'
22

33
module Lit
44
module Api
55
module V1
66
class LocalesController < Api::V1::BaseController
77
def index
88
@locales = Locale.all
9-
render :json=>@locales.as_json(:root=>false, :only=>[:id, :locale])
9+
render json: @locales.as_json(root: false, only: [:id, :locale])
1010
end
1111
end
1212
end
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_dependency "lit/api/v1/base_controller"
1+
require_dependency 'lit/api/v1/base_controller'
22

33
module Lit
44
class Api::V1::LocalizationKeysController < Api::V1::BaseController
@@ -9,8 +9,7 @@ def index
99
else
1010
@localization_keys = @localization_keys.all
1111
end
12-
render :json=>@localization_keys.as_json(:root=>false, :only=>[:id, :localization_key])
12+
render json: @localization_keys.as_json(root: false, only: [:id, :localization_key])
1313
end
1414
end
1515
end
16-

app/controllers/lit/api/v1/localizations_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def index
77
else
88
@localizations = @localizations.all
99
end
10-
render :json=>@localizations.as_json(:root=>false, :only=>[:id, :localization_key_id, :locale_id], :methods=>[:value, :localization_key_str, :locale_str])
10+
render json: @localizations.as_json(root: false, only: [:id, :localization_key_id, :locale_id], methods: [:value, :localization_key_str, :locale_str])
1111
end
1212

1313
def last_change
1414
@localization = Localization.order('updated_at DESC').first
15-
render :json=>@localization.as_json(:root=>false, :only=>[], :methods=>[:last_change])
15+
render json: @localization.as_json(root: false, only: [], methods: [:last_change])
1616
end
1717
end
1818
end

app/controllers/lit/application_controller.rb

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ class ApplicationController < ActionController::Base
55
after_filter :restore_hits_counter
66

77
private
8-
def authenticate
9-
if Lit.authentication_function.present?
10-
send(Lit.authentication_function)
11-
end
12-
end
138

14-
def stop_hits_counter
15-
Lit.init.cache.stop_hits_counter
16-
end
9+
def authenticate
10+
return unless Lit.authentication_function.present?
1711

18-
def restore_hits_counter
19-
Lit.init.cache.restore_hits_counter
20-
end
12+
send(Lit.authentication_function)
13+
end
14+
15+
def stop_hits_counter
16+
Lit.init.cache.stop_hits_counter
17+
end
18+
19+
def restore_hits_counter
20+
Lit.init.cache.restore_hits_counter
21+
end
2122
end
2223
end

app/controllers/lit/dashboard_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_dependency "lit/application_controller"
1+
require_dependency 'lit/application_controller'
22

33
module Lit
44
class DashboardController < ::Lit::ApplicationController

app/controllers/lit/incomming_localizations_controller.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_dependency "lit/application_controller"
1+
require_dependency 'lit/application_controller'
22

33
module Lit
44
class IncommingLocalizationsController < ApplicationController
@@ -35,8 +35,9 @@ def destroy
3535
end
3636

3737
private
38-
def find_source
39-
@source = Source.find(params[:source_id].to_i)
40-
end
38+
39+
def find_source
40+
@source = Source.find(params[:source_id].to_i)
41+
end
4142
end
4243
end

app/controllers/lit/locales_controller.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
require_dependency "lit/application_controller"
1+
require_dependency 'lit/application_controller'
22

33
module Lit
44
class LocalesController < ApplicationController
55
def index
66
@locales = Locale.ordered.all
7-
7+
88
respond_to do |format|
99
format.html # index.html.erb
1010
format.json { render json: @locales }
1111
end
1212
end
13-
13+
1414
def hide
1515
@locale = Locale.find(params[:id])
1616
@locale.is_hidden = !@locale.is_hidden?
1717
@locale.save
1818
respond_to :js
1919
end
20-
20+
2121
def destroy
2222
@locale = Locale.find(params[:id])
2323
@locale.destroy
24-
24+
2525
respond_to do |format|
2626
format.html { redirect_to locales_url }
2727
format.json { head :no_content }
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module Lit
22
class LocalizationKeysController < ::Lit::ApplicationController
3-
before_filter :get_localization_scope, :except=>[:destroy]
3+
before_filter :get_localization_scope, except: [:destroy]
44

55
def index
66
get_localization_keys
77
end
88

99
def starred
10-
@scope = @scope.where(:is_starred=>true)
10+
@scope = @scope.where(is_starred: true)
1111

1212
if @scope.respond_to?(:page)
1313
@scope = @scope.page(params[:page])
1414
end
1515
get_localization_keys
16-
render :action=>:index
16+
render action: :index
1717
end
1818

1919
def star
@@ -33,72 +33,72 @@ def destroy
3333
end
3434

3535
private
36-
def get_localization_scope
37-
@search_options = params.slice(*valid_keys)
38-
@search_options[:include_completed] = '1' if @search_options.empty?
39-
@scope = LocalizationKey.uniq.preload(:localizations => :locale).search(@search_options)
40-
end
4136

42-
def get_localization_keys
43-
key_parts = @search_options[:key_prefix].to_s.split('.').length
44-
@prefixes = @scope.reorder(nil).uniq.pluck(:localization_key).map{|lk| lk.split('.').shift(key_parts+1).join('.') }.uniq.sort
45-
if @search_options[:key_prefix].present?
46-
parts = @search_options[:key_prefix].split('.')
47-
@parent_prefix = parts[0,parts.length-1].join('.')
48-
end
49-
if @scope.respond_to?(:page)
50-
@localization_keys = @scope.page(params[:page])
51-
else
52-
@localization_keys = @scope.all
53-
end
54-
end
37+
def get_localization_scope
38+
@search_options = params.slice(*valid_keys)
39+
@search_options[:include_completed] = '1' if @search_options.empty?
40+
@scope = LocalizationKey.uniq.preload(localizations: :locale).search(@search_options)
41+
end
5542

56-
def valid_keys
57-
%w( key include_completed key_prefix order )
43+
def get_localization_keys
44+
key_parts = @search_options[:key_prefix].to_s.split('.').length
45+
@prefixes = @scope.reorder(nil).uniq.pluck(:localization_key).map { |lk| lk.split('.').shift(key_parts + 1).join('.') }.uniq.sort
46+
if @search_options[:key_prefix].present?
47+
parts = @search_options[:key_prefix].split('.')
48+
@parent_prefix = parts[0, parts.length - 1].join('.')
49+
end
50+
if @scope.respond_to?(:page)
51+
@localization_keys = @scope.page(params[:page])
52+
else
53+
@localization_keys = @scope.all
5854
end
55+
end
5956

60-
def grouped_localizations
61-
@_grouped_localizations ||= begin
62-
{}.tap do |hash|
63-
@localization_keys.each do |lk|
64-
hash[lk] = {}
65-
lk.localizations.each do |l|
66-
hash[lk][l.locale.locale.to_sym] = l
67-
end
57+
def valid_keys
58+
%w( key include_completed key_prefix order )
59+
end
60+
61+
def grouped_localizations
62+
@_grouped_localizations ||= begin
63+
{}.tap do |hash|
64+
@localization_keys.each do |lk|
65+
hash[lk] = {}
66+
lk.localizations.each do |l|
67+
hash[lk][l.locale.locale.to_sym] = l
6868
end
6969
end
7070
end
7171
end
72+
end
7273

73-
def localization_for(locale, localization_key)
74-
@_localization_for ||= {}
75-
key = [locale, localization_key]
76-
ret = @_localization_for[key]
77-
if ret == false
78-
nil
79-
elsif ret.nil?
80-
ret = grouped_localizations[localization_key][locale]
81-
unless ret
82-
Lit.init.cache.refresh_key("#{locale}.#{localization_key.localization_key}")
83-
ret = localization_key.localizations.where(:locale_id=>Lit.init.cache.find_locale(locale).id).first
84-
end
85-
@_localization_for[key] = ret ? ret : false
86-
else
87-
ret
74+
def localization_for(locale, localization_key)
75+
@_localization_for ||= {}
76+
key = [locale, localization_key]
77+
ret = @_localization_for[key]
78+
if ret == false
79+
nil
80+
elsif ret.nil?
81+
ret = grouped_localizations[localization_key][locale]
82+
unless ret
83+
Lit.init.cache.refresh_key("#{locale}.#{localization_key.localization_key}")
84+
ret = localization_key.localizations.where(locale_id: Lit.init.cache.find_locale(locale).id).first
8885
end
89-
86+
@_localization_for[key] = ret ? ret : false
87+
else
88+
ret
9089
end
90+
end
9191

92-
helper_method :localization_for
92+
helper_method :localization_for
9393

94-
def has_versions?(localization)
95-
@_versions ||= begin
96-
ids = grouped_localizations.values.map(&:values).flatten.map(&:id)
97-
Lit::Localization.where(:id => ids).joins(:versions).group("#{Lit::Localization.quoted_table_name}.id").count
98-
end
99-
@_versions[localization.id].to_i > 0
94+
def has_versions?(localization)
95+
@_versions ||= begin
96+
ids = grouped_localizations.values.map(&:values).flatten.map(&:id)
97+
Lit::Localization.where(id: ids).joins(:versions).group("#{Lit::Localization.quoted_table_name}.id").count
10098
end
99+
@_versions[localization.id].to_i > 0
100+
end
101101

102-
helper_method :has_versions?
102+
helper_method :has_versions?
103103
end
104104
end

app/controllers/lit/localizations_controller.rb

+16-15
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@ def previous_versions
2222
end
2323

2424
private
25-
def find_localization_key
26-
@localization_key = Lit::LocalizationKey.find(params[:localization_key_id])
27-
end
2825

29-
def find_localization
30-
@localization = @localization_key.localizations.find(params[:id])
31-
end
26+
def find_localization_key
27+
@localization_key = Lit::LocalizationKey.find(params[:localization_key_id])
28+
end
3229

33-
def clear_params
34-
if defined?(::ActionController::StrongParameters)
35-
# allow translated_value to be an array
36-
if @localization.value.is_a?(Array)
37-
params.require(:localization).permit(:locale_id, :translated_value => [])
38-
else
39-
params.require(:localization).permit(:locale_id, :translated_value)
40-
end
30+
def find_localization
31+
@localization = @localization_key.localizations.find(params[:id])
32+
end
33+
34+
def clear_params
35+
if defined?(::ActionController::StrongParameters)
36+
# allow translated_value to be an array
37+
if @localization.value.is_a?(Array)
38+
params.require(:localization).permit(:locale_id, translated_value: [])
4139
else
42-
params[:localization].is_a?(Hash) ? params[:localization].slice(:translated_value, :locale_id) : {}
40+
params.require(:localization).permit(:locale_id, :translated_value)
4341
end
42+
else
43+
params[:localization].is_a?(Hash) ? params[:localization].slice(:translated_value, :locale_id) : {}
4444
end
45+
end
4546
end
4647
end

0 commit comments

Comments
 (0)