mighty_grid 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -1
  3. data/.travis.yml +10 -3
  4. data/Appraisals +6 -3
  5. data/Gemfile +8 -3
  6. data/Rakefile +5 -6
  7. data/features/filtering.feature +14 -13
  8. data/features/step_definitions/steps.rb +4 -4
  9. data/features/support/capybara.rb +8 -0
  10. data/features/support/database_cleaner.rb +2 -2
  11. data/features/support/env.rb +4 -3
  12. data/features/support/paths.rb +4 -4
  13. data/gemfiles/rails_32.gemfile +9 -4
  14. data/gemfiles/rails_40.gemfile +7 -2
  15. data/gemfiles/rails_41.gemfile +7 -2
  16. data/lib/generators/mighty_grid/install_generator.rb +4 -2
  17. data/lib/generators/mighty_grid/templates/mighty_grid_config.rb +1 -1
  18. data/lib/mighty_grid/base.rb +30 -33
  19. data/lib/mighty_grid/column.rb +16 -18
  20. data/lib/mighty_grid/config.rb +1 -1
  21. data/lib/mighty_grid/engine.rb +1 -3
  22. data/lib/mighty_grid/filter_renderer.rb +24 -24
  23. data/lib/mighty_grid/grid_renderer.rb +8 -6
  24. data/lib/mighty_grid/helpers/mighty_grid_view_helpers.rb +71 -74
  25. data/lib/mighty_grid/kaminari_monkey_patching.rb +1 -1
  26. data/lib/mighty_grid/mighty_grid_controller.rb +4 -6
  27. data/lib/mighty_grid/mighty_grid_ext.rb +2 -2
  28. data/lib/mighty_grid/mighty_grid_misc.rb +2 -4
  29. data/lib/mighty_grid/version.rb +1 -1
  30. data/lib/mighty_grid.rb +1 -1
  31. data/mighty_grid.gemspec +11 -11
  32. data/spec/config_spec.rb +27 -27
  33. data/spec/dummy/Rakefile +6 -0
  34. data/spec/dummy/app/assets/images/.keep +0 -0
  35. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  36. data/spec/dummy/app/assets/stylesheets/application.css +16 -0
  37. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  38. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  39. data/spec/dummy/app/controllers/users_controller.rb +5 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  41. data/spec/dummy/app/mailers/.keep +0 -0
  42. data/spec/dummy/app/models/.keep +0 -0
  43. data/spec/dummy/app/models/company.rb +3 -0
  44. data/spec/dummy/app/models/concerns/.keep +0 -0
  45. data/spec/dummy/app/models/user.rb +3 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/spec/{fake_app/views/index.html.erb → dummy/app/views/users/index.html} +0 -6
  48. data/spec/dummy/bin/bundle +3 -0
  49. data/spec/dummy/bin/rails +4 -0
  50. data/spec/dummy/bin/rake +4 -0
  51. data/spec/dummy/config/application.rb +31 -0
  52. data/spec/dummy/config/boot.rb +5 -0
  53. data/spec/dummy/config/database.yml.travis +28 -0
  54. data/spec/dummy/config/environment.rb +9 -0
  55. data/spec/dummy/config/environments/development.rb +38 -0
  56. data/spec/dummy/config/environments/production.rb +83 -0
  57. data/spec/dummy/config/environments/test.rb +39 -0
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  60. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  61. data/spec/dummy/config/initializers/inflections.rb +16 -0
  62. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  63. data/spec/dummy/config/initializers/secret_token.rb +16 -0
  64. data/spec/dummy/config/initializers/session_store.rb +3 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/spec/dummy/config/locales/en.yml +23 -0
  67. data/spec/dummy/config/routes.rb +10 -0
  68. data/spec/dummy/config/secrets.yml +22 -0
  69. data/spec/dummy/config.ru +4 -0
  70. data/spec/dummy/db/migrate/20140727125647_create_users.rb +12 -0
  71. data/spec/dummy/db/migrate/20140727141742_create_companies.rb +9 -0
  72. data/spec/dummy/db/schema.rb +31 -0
  73. data/spec/dummy/lib/assets/.keep +0 -0
  74. data/spec/dummy/public/404.html +67 -0
  75. data/spec/dummy/public/422.html +67 -0
  76. data/spec/dummy/public/500.html +66 -0
  77. data/spec/dummy/public/favicon.ico +0 -0
  78. data/spec/lib/base_spec.rb +31 -54
  79. data/spec/lib/column_spec.rb +13 -13
  80. data/spec/lib/generators/install_generator_spec.rb +7 -7
  81. data/spec/spec_helper.rb +5 -3
  82. data/spec/support/capybara.rb +0 -4
  83. data/spec/support/database_cleaner.rb +1 -5
  84. metadata +94 -12
  85. data/spec/fake_app/config/database.yml.example +0 -14
  86. data/spec/fake_app/models/active_record.rb +0 -25
  87. data/spec/fake_app/models/config.rb +0 -5
  88. data/spec/fake_app/rails_app.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9fb8a05f406c93425c49c6bc860276ab6d7140b
4
- data.tar.gz: 6245a2f298bf5db56c004e3fb81d13413993dfcb
3
+ metadata.gz: 74b8144f9e7e58cdc96ca3d0b807c64480fb1358
4
+ data.tar.gz: 3df768d2465fef24ef982f16b48c1f63c9835f39
5
5
  SHA512:
6
- metadata.gz: a4867e8238ab8c79d6c525bc5d1b325c6d57c7ab010e0a547bd66583e69cc17f87ee7de682b961e6adb9b9f7bcae40e0fb2f87d6a5a8585bd78a4984f6214880
7
- data.tar.gz: 12f58aca2256556dca79d1932f9008a62212206b2d80fdbe4e0f0e0d7001bf9b17d137f6737522c7725b295e1d47a7f99723d34fba228ca1ad19e40dc9a3fe5d
6
+ metadata.gz: c198e16b636905e23ecdf31a2c9fc76c2275a4db88aee84df62ebf5e7532a78a1e25c925af505413c4886dafa1aff02562fb9f294a89815e2d16132765972717
7
+ data.tar.gz: c5425779bef23b7b99d6b7b61531cc26990c73a8e86ba9e95ed652af42433645ab2f75dd09a0db460b4dd89dc34a5cfa47d3cc29d3c21ad0d6725539d8d4c510
data/.gitignore CHANGED
@@ -17,4 +17,10 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  log
20
- spec/fake_app/config/*.yml
20
+ database.yml
21
+
22
+ spec/dummy/db/*.sqlite3
23
+ spec/dummy/db/*.sqlite3-journal
24
+ spec/dummy/log/*.log
25
+ spec/dummy/tmp/
26
+ spec/dummy/.sass-cache
data/.travis.yml CHANGED
@@ -2,11 +2,14 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.1
5
+ - ruby-head
5
6
 
6
- script: bundle exec rake spec cucumber
7
+ script:
8
+ - bundle exec rake -f spec/dummy/Rakefile db:migrate
9
+ - bundle exec rake spec cucumber
7
10
 
8
11
  before_script:
9
- - cp spec/fake_app/config/database.yml.example spec/fake_app/config/database.yml
12
+ - cp spec/dummy/config/database.yml.travis spec/dummy/config/database.yml
10
13
  - mysql -e 'create database mg_test'
11
14
  - psql -c 'create database mg_test' -U postgres
12
15
 
@@ -23,4 +26,8 @@ gemfile:
23
26
  addons:
24
27
  code_climate:
25
28
  repo_token: 47bc411a11ccfed015bf25395d8204600c899e530c1c4beed1b7197aa61c6fb6
26
- postgresql: "9.3"
29
+ postgresql: "9.3"
30
+
31
+ matrix:
32
+ allow_failures:
33
+ - rvm: ruby-head
data/Appraisals CHANGED
@@ -1,14 +1,17 @@
1
1
  appraise "rails_32" do
2
- gem "rails", "~> 3.2.15"
3
- gem "activerecord", "~> 3.2.15", require: 'active_record'
2
+ gem "rails", "~> 3.2.19"
3
+ gem "activerecord", "~> 3.2.19", require: 'active_record'
4
+ gem 'coffee-rails', '~> 3.2.0'
4
5
  end
5
6
 
6
7
  appraise "rails_40" do
7
8
  gem "rails", "~> 4.0.0"
8
9
  gem "activerecord", "~> 4.0.0", require: 'active_record'
10
+ gem 'coffee-rails', '~> 4.0.0'
9
11
  end
10
12
 
11
13
  appraise "rails_41" do
12
14
  gem "rails", "~> 4.1.0"
13
15
  gem "activerecord", "~> 4.1.0", require: 'active_record'
14
- end
16
+ gem 'coffee-rails', '~> 4.0.0'
17
+ end
data/Gemfile CHANGED
@@ -2,16 +2,21 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'uglifier', '>= 1.3.0' # Use Uglifier as compressor for JavaScript assets
6
+ gem 'jquery-rails' # Use jquery as the JavaScript library
7
+
5
8
  group :test do
6
9
  gem 'sqlite3'
7
10
  gem "generator_spec"
8
- gem 'capybara'
11
+ gem 'capybara', require: false
9
12
  gem 'database_cleaner'
10
- gem 'cucumber-rails'
13
+ gem 'cucumber-rails', require: false
11
14
  gem 'spreewald'
15
+ gem 'poltergeist'
16
+ gem 'launchy'
12
17
 
13
18
  gem 'coveralls', require: false
14
19
  gem "codeclimate-test-reporter", require: nil
15
20
  gem 'pg', require: false
16
21
  gem 'mysql2', require: false
17
- end
22
+ end
data/Rakefile CHANGED
@@ -1,16 +1,15 @@
1
- require "bundler/gem_tasks"
2
1
  require 'appraisal'
3
2
  require 'rspec/core/rake_task'
4
3
  require 'cucumber/rake/task'
5
4
 
6
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
7
- task :default => :appraisal
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ if !ENV['APPRAISAL_INITIALIZED'] && !ENV['TRAVIS']
8
+ task default: :appraisal
8
9
  end
9
10
 
10
11
  desc 'Test the paperclip plugin.'
11
12
  RSpec::Core::RakeTask.new(:spec)
12
13
 
13
14
  desc 'Run integration test'
14
- Cucumber::Rake::Task.new do |t|
15
- t.cucumber_opts = %w{--format progress}
16
- end
15
+ Cucumber::Rake::Task.new
@@ -27,16 +27,17 @@ Feature: Filtering
27
27
  And I should see "user101"
28
28
  And I should see "1 of 1"
29
29
 
30
- # Scenario: Reset filter
31
- # Given I am on the list of users page
32
- # When I fill in "Name" with "user001"
33
- # And I select "Admin" from "Role"
34
- # And I check "Banned"
35
- # And I press "Apply changes"
36
- # Then the "Name" field should contain "user001"
37
- # And "Admin" should be selected for "Role"
38
- # And the "Banned" checkbox should be checked
39
- # When I press "Reset changes"
40
- # Then the "Name" field should contain ""
41
- # And nothing should be selected for "Role"
42
- # And the "Banned" checkbox should not be checked
30
+ @javascript
31
+ Scenario: Reset filter
32
+ Given I am on the list of users page
33
+ When I fill in "Name" with "user001"
34
+ And I select "Admin" from "Role"
35
+ And I check "Banned"
36
+ And I press "Apply changes"
37
+ Then the "Name" field should contain "user001"
38
+ And "Admin" should be selected for "Role"
39
+ And the "Banned" checkbox should be checked
40
+ When I press "Reset changes"
41
+ Then the "Name" field should contain ""
42
+ And nothing should be selected for "Role"
43
+ And the "Banned" checkbox should not be checked
@@ -1,5 +1,5 @@
1
1
  Given /^I generate (\d+) users$/ do |n|
2
- 1.upto(n.to_i) {|i| User.create! :name => "user#{'%03d' % i}" }
3
- User.create! :name => "admin#{'%03d' % 1}", role: :admin
4
- User.create! :name => "user#{'%03d' % (n.to_i + 1)}", is_banned: true
5
- end
2
+ 1.upto(n.to_i) { |i| User.create! name: "user#{format('%03d', i)}" }
3
+ User.create! name: "admin#{format('%03d', 1)}", role: :admin
4
+ User.create! name: "user#{format('%03d', (n.to_i + 1))}", is_banned: true
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'capybara/poltergeist'
2
+
3
+ # Capybara.register_driver :poltergeist_debug do |app|
4
+ # Capybara::Poltergeist::Driver.new(app, :inspector => true)
5
+ # end
6
+
7
+ Capybara.javascript_driver = :poltergeist
8
+ # Capybara.javascript_driver = :poltergeist_debug
@@ -4,9 +4,9 @@ begin
4
4
 
5
5
  DatabaseCleaner.strategy = :truncation
6
6
  rescue NameError
7
- raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
7
+ raise 'You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.'
8
8
  end
9
9
 
10
10
  # Around do |scenario, block|
11
11
  # DatabaseCleaner.cleaning(&block)
12
- # end
12
+ # end
@@ -4,14 +4,15 @@ begin
4
4
  rescue LoadError
5
5
  end
6
6
 
7
- require 'capybara/cucumber'
8
7
  require 'bundler/setup'
9
8
  Bundler.require
10
9
 
10
+ require 'capybara/cucumber'
11
+
11
12
  if defined? Rails
12
- require_relative '../../spec/fake_app/rails_app'
13
+ require File.expand_path("../../../spec/dummy/config/environment.rb", __FILE__)
13
14
  end
14
15
 
15
16
  require 'spreewald/web_steps'
16
17
  require 'spreewald/table_steps'
17
- require 'spreewald/development_steps'
18
+ require 'spreewald/development_steps'
@@ -15,13 +15,13 @@ module NavigationHelpers
15
15
  begin
16
16
  page_name =~ /^the (.*) page$/
17
17
  path_components = $1.split(/\s+/)
18
- self.send(path_components.push('path').join('_').to_sym)
18
+ send(path_components.push('path').join('_').to_sym)
19
19
  rescue NoMethodError, ArgumentError
20
- raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
21
- "Now, go and add a mapping in #{__FILE__}"
20
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" \
21
+ "Now, go and add a mapping in #{__FILE__}"
22
22
  end
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
- World(NavigationHelpers)
27
+ World(NavigationHelpers)
@@ -2,16 +2,21 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 3.2.15"
6
- gem "activerecord", "~> 3.2.15", :require => "active_record"
5
+ gem "rails", "~> 3.2.19"
6
+ gem "activerecord", "~> 3.2.19", :require => "active_record"
7
+ gem "coffee-rails", "~> 3.2.0"
7
8
 
8
9
  group :test do
9
10
  gem "sqlite3"
10
11
  gem "generator_spec"
11
- gem "capybara"
12
+ gem "capybara", :require => false
12
13
  gem "database_cleaner"
13
- gem "cucumber-rails"
14
+ gem "cucumber-rails", :require => false
14
15
  gem "spreewald"
16
+ gem "poltergeist"
17
+ gem "launchy"
18
+ gem "uglifier", ">= 1.3.0"
19
+ gem "jquery-rails"
15
20
  gem "coveralls", :require => false
16
21
  gem "codeclimate-test-reporter", :require => nil
17
22
  gem "pg", :require => false
@@ -4,14 +4,19 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.0.0"
6
6
  gem "activerecord", "~> 4.0.0", :require => "active_record"
7
+ gem "coffee-rails", "~> 4.0.0"
7
8
 
8
9
  group :test do
9
10
  gem "sqlite3"
10
11
  gem "generator_spec"
11
- gem "capybara"
12
+ gem "capybara", :require => false
12
13
  gem "database_cleaner"
13
- gem "cucumber-rails"
14
+ gem "cucumber-rails", :require => false
14
15
  gem "spreewald"
16
+ gem "poltergeist"
17
+ gem "launchy"
18
+ gem "uglifier", ">= 1.3.0"
19
+ gem "jquery-rails"
15
20
  gem "coveralls", :require => false
16
21
  gem "codeclimate-test-reporter", :require => nil
17
22
  gem "pg", :require => false
@@ -4,14 +4,19 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.1.0"
6
6
  gem "activerecord", "~> 4.1.0", :require => "active_record"
7
+ gem "coffee-rails", "~> 4.0.0"
7
8
 
8
9
  group :test do
9
10
  gem "sqlite3"
10
11
  gem "generator_spec"
11
- gem "capybara"
12
+ gem "capybara", :require => false
12
13
  gem "database_cleaner"
13
- gem "cucumber-rails"
14
+ gem "cucumber-rails", :require => false
14
15
  gem "spreewald"
16
+ gem "poltergeist"
17
+ gem "launchy"
18
+ gem "uglifier", ">= 1.3.0"
19
+ gem "jquery-rails"
15
20
  gem "coveralls", :require => false
16
21
  gem "codeclimate-test-reporter", :require => nil
17
22
  gem "pg", :require => false
@@ -1,9 +1,11 @@
1
+ require 'rails/generators'
2
+
1
3
  module MightyGrid
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
4
6
  source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
7
 
6
- desc "Copies MightyGrid configuration and locale files to your application."
8
+ desc 'Copies MightyGrid configuration and locale files to your application.'
7
9
 
8
10
  def copy_config_file
9
11
  template 'mighty_grid_config.rb', 'config/initializers/mighty_grid_config.rb'
@@ -14,4 +16,4 @@ module MightyGrid
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -12,4 +12,4 @@ MightyGrid.configure do |config|
12
12
  # config.table_class = ''
13
13
  # config.header_tr_class = ''
14
14
  # config.pagination_template = 'mighty_grid'
15
- end
15
+ end
@@ -1,7 +1,5 @@
1
1
  module MightyGrid
2
-
3
2
  class Base
4
-
5
3
  attr_reader :klass, :name, :relation, :options, :mg_params, :controller
6
4
  attr_accessor :output_buffer, :filters
7
5
 
@@ -11,13 +9,13 @@ module MightyGrid
11
9
  @filters = {}
12
10
 
13
11
  @options = {
14
- :page => 1,
15
- :per_page => MightyGrid.config.per_page,
16
- :name => MightyGrid.config.grid_name,
17
- :include => nil,
18
- :joins => nil,
19
- :conditions => nil,
20
- :group => nil
12
+ page: 1,
13
+ per_page: MightyGrid.config.per_page,
14
+ name: MightyGrid.config.grid_name,
15
+ include: nil,
16
+ joins: nil,
17
+ conditions: nil,
18
+ group: nil
21
19
  }
22
20
 
23
21
  opts.assert_valid_keys(@options.keys)
@@ -35,13 +33,13 @@ module MightyGrid
35
33
  def read
36
34
  apply_filters
37
35
  @relation = @relation.order("#{@mg_params[:order]} #{current_order_direction.to_sym}") if @mg_params[:order].present? && current_order_direction.present?
38
- @relation = @relation.
39
- page(@mg_params[:page]).
40
- per(@mg_params[:per_page]).
41
- includes(@options[:include]).
42
- joins(@options[:joins]).
43
- where(@options[:conditions]).
44
- group(@options[:group])
36
+ @relation = @relation
37
+ .page(@mg_params[:page])
38
+ .per(@mg_params[:per_page])
39
+ .includes(@options[:include])
40
+ .joins(@options[:joins])
41
+ .where(@options[:conditions])
42
+ .group(@options[:group])
45
43
  end
46
44
 
47
45
  # Apply filters
@@ -58,19 +56,17 @@ module MightyGrid
58
56
  next if filter_value.blank? || !model.column_names.include?(name)
59
57
 
60
58
  if model && model.superclass == ActiveRecord::Base
61
- filter_type = model.columns_hash[name].type
59
+ field_type = model.columns_hash[name].type
62
60
  else
63
61
  next
64
62
  end
65
63
 
66
- field_type ||= model.columns_hash[name].type
67
64
  table_name = model.table_name
68
-
69
- if @filters.has_key?(filter_name.to_sym) && @filters[filter_name.to_sym].is_a?(Array)
65
+ if @filters.key?(filter_name.to_sym) && @filters[filter_name.to_sym].is_a?(Array)
70
66
  @relation = @relation.where(table_name => { filter_name => filter_value })
71
67
  elsif field_type == :boolean
72
- value = ['true', '1', 't'].include?(filter_value) ? true : false
73
- @relation = @relation.where(table_name => {filter_name => value})
68
+ value = %w(true 1 t).include?(filter_value) ? true : false
69
+ @relation = @relation.where(table_name => { filter_name => value })
74
70
  elsif [:string, :text].include?(field_type)
75
71
  @relation = @relation.where("#{table_name}.#{name} #{like_operator} ?", "%#{filter_value}%")
76
72
  end
@@ -89,14 +85,14 @@ module MightyGrid
89
85
  if current_grid_params
90
86
  @mg_params.merge!(current_grid_params.symbolize_keys)
91
87
  if @mg_params[:order].present? && !@mg_params[:order].to_s.include?('.')
92
- @mg_params[:order] = "#{klass.table_name}.#{@mg_params[:order]}"
88
+ @mg_params[:order] = "#{klass.table_name}.#{@mg_params[:order]}"
93
89
  end
94
90
  end
95
91
  end
96
92
 
97
93
  # Get current grid parameter by name
98
94
  def get_current_grid_param(name)
99
- current_grid_params.has_key?(name) ? current_grid_params[name] : nil
95
+ current_grid_params.key?(name) ? current_grid_params[name] : nil
100
96
  end
101
97
 
102
98
  # Get filter parameters
@@ -105,7 +101,9 @@ module MightyGrid
105
101
  end
106
102
 
107
103
  # Get filter parameter name
108
- def filter_param_name; 'f' end
104
+ def filter_param_name
105
+ 'f'
106
+ end
109
107
 
110
108
  # Get filter name by field
111
109
  def get_filter_name(field, model = nil)
@@ -122,18 +120,18 @@ module MightyGrid
122
120
  def order_params(attribute, model = nil, direction = nil)
123
121
  order = model.present? ? "#{model.table_name}.#{attribute}" : attribute.to_s
124
122
  direction ||= order == current_grid_params['order'] ? another_order_direction : 'asc'
125
- {@name => {order: order, order_direction: direction}}
123
+ { @name => { order: order, order_direction: direction } }
126
124
  end
127
125
 
128
126
  # Get current order direction if current order parameter coincides with the received parameter
129
127
  def get_active_order_direction(parameters)
130
- (parameters[@name]['order'] == current_grid_params['order']) ? current_order_direction : nil
128
+ parameters[@name]['order'] == current_grid_params['order'] ? current_order_direction : nil
131
129
  end
132
130
 
133
131
  # Get current order direction
134
132
  def current_order_direction
135
133
  direction = nil
136
- if current_grid_params.has_key?('order_direction') && ['asc', 'desc'].include?(current_grid_params['order_direction'].downcase)
134
+ if current_grid_params.key?('order_direction') && %w(asc desc).include?(current_grid_params['order_direction'].downcase)
137
135
  direction = current_grid_params['order_direction'].downcase
138
136
  end
139
137
  direction
@@ -141,17 +139,16 @@ module MightyGrid
141
139
 
142
140
  # Get another order direction
143
141
  def another_order_direction
144
- (current_grid_params.has_key?('order_direction')) ? (['asc', 'desc'] - [current_grid_params['order_direction'].to_s]).first : MightyGrid.config.order_direction
142
+ current_grid_params.key?('order_direction') ? (%w(asc desc) - [current_grid_params['order_direction'].to_s]).first : MightyGrid.config.order_direction
145
143
  end
146
144
 
147
- # Get <tt>like</tt> or <tt>ilike</tt> operator depending on the database adapter
145
+ # Get <tt>like</tt> or <tt>ilike</tt> operator depending on the database adapter
148
146
  def like_operator
149
147
  if ActiveRecord::ConnectionAdapters.const_defined?(:PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
150
148
  'ILIKE'
151
149
  else
152
- 'LIKE'
150
+ 'LIKE'
153
151
  end
154
152
  end
155
-
156
153
  end
157
- end
154
+ end
@@ -1,14 +1,13 @@
1
1
  module MightyGrid
2
2
  class Column
3
-
4
3
  attr_reader :attribute, :attrs, :th_attrs, :options, :title, :model, :partial
5
4
  attr_accessor :render_value
6
5
 
7
- def initialize(options={}, &block)
6
+ def initialize(options = {}, &block)
8
7
  @attrs = {}
9
8
  @th_attrs = {}
10
9
 
11
- @attribute = options.delete(:attribute) if options.has_key?(:attribute)
10
+ @attribute = options.delete(:attribute) if options.key?(:attribute)
12
11
 
13
12
  @options ||= options
14
13
 
@@ -19,25 +18,24 @@ module MightyGrid
19
18
  end
20
19
 
21
20
  @model = @options[:model]
22
- raise MightyGridArgumentError.new("Model of field for filtering should have type ActiveRecord") if @model && @model.superclass != ActiveRecord::Base
23
-
24
- @attrs = @options[:html] if @options.has_key?(:html)
25
- @th_attrs = @options[:th_html] if @options.has_key?(:th_html)
26
- @title = @options.has_key?(:title) && @options[:title] || ''
21
+ fail MightyGridArgumentError.new('Model of field for filtering should have type ActiveRecord') if @model && @model.superclass != ActiveRecord::Base
22
+
23
+ @attrs = @options[:html] if @options.key?(:html)
24
+ @th_attrs = @options[:th_html] if @options.key?(:th_html)
25
+ @title = @options.key?(:title) && @options[:title] || ''
27
26
  end
28
27
 
29
28
  def render(record)
30
29
  case @render_value
31
- when String, Symbol
32
- rec = @model ? record.send(@model.to_s.underscore) : record
33
- return rec[@render_value]
34
- when Proc
35
- value = @render_value.call(record)
36
- return ERB::Util.h(value).to_s.html_safe
37
- else
38
- # raise
30
+ when String, Symbol
31
+ rec = @model ? record.send(@model.to_s.underscore) : record
32
+ return rec[@render_value]
33
+ when Proc
34
+ value = @render_value.call(record)
35
+ return ERB::Util.h(value).to_s.html_safe
36
+ else
37
+ # raise
39
38
  end
40
39
  end
41
-
42
40
  end
43
- end
41
+ end
@@ -46,4 +46,4 @@ module MightyGrid
46
46
  config.header_tr_class = ''
47
47
  config.pagination_theme = 'mighty_grid'
48
48
  end
49
- end
49
+ end
@@ -1,5 +1,4 @@
1
1
  module MightyGrid
2
-
3
2
  class MightyGridEngine < ::Rails::Engine
4
3
  initializer 'mighty_grid_railtie.configure_rails_initialization' do |app|
5
4
 
@@ -16,5 +15,4 @@ module MightyGrid
16
15
 
17
16
  end
18
17
  end
19
-
20
- end
18
+ end
@@ -17,17 +17,17 @@ module MightyGrid
17
17
  end
18
18
 
19
19
  # Get <tt>input</tt> HTML tag
20
- def text_field(name, options={})
20
+ def text_field(name, options = {})
21
21
  f_options = filter_options(name, options)
22
22
  text_field_tag(@grid.get_filter_name(name, f_options[:model]), get_filter_param(name, f_options[:model]), options)
23
23
  end
24
24
 
25
25
  # Get <tt>select</tt> HTML tag
26
- def select(name, option_tags=nil, options={})
26
+ def select(name, option_tags = nil, options = {})
27
27
  @grid.filters[name] = option_tags
28
28
  selected = nil
29
- selected = options.delete(:selected) if options.has_key?(:selected)
30
-
29
+ selected = options.delete(:selected) if options.key?(:selected)
30
+
31
31
  f_options = filter_options(name, options)
32
32
 
33
33
  selected = get_filter_param(name, f_options[:model]) if get_filter_param(name, f_options[:model])
@@ -41,44 +41,44 @@ module MightyGrid
41
41
  checked = true if get_filter_param(name)
42
42
 
43
43
  f_options = filter_options(name, options)
44
-
44
+
45
45
  check_box_tag(@grid.get_filter_name(name, f_options[:model]), value, checked, options)
46
46
  end
47
47
 
48
48
  # Get button for Apply filter changes
49
49
  def submit(content = nil, options = {})
50
- content = I18n.t("mighty_grid.filters.submit", default: 'Apply changes') if content.blank?
50
+ content = I18n.t('mighty_grid.filters.submit', default: 'Apply changes') if content.blank?
51
51
  options.merge!(type: :submit)
52
52
  content_tag(:button, content, options)
53
53
  end
54
54
 
55
55
  # Get button for Reset filter changes
56
56
  def reset(content = nil, options = {})
57
- content = I18n.t("mighty_grid.filters.reset", default: 'Reset changes') if content.blank?
57
+ content = I18n.t('mighty_grid.filters.reset', default: 'Reset changes') if content.blank?
58
58
  options.merge!(type: :reset)
59
59
  content_tag(:button, content, options)
60
60
  end
61
61
 
62
62
  private
63
63
 
64
- def get_filter_param(name, model = nil)
65
- filter_name = model ? "#{model.table_name}.#{name}" : name
66
- @grid.filter_params.has_key?(filter_name) ? @grid.filter_params[filter_name] : nil
67
- end
64
+ def get_filter_param(name, model = nil)
65
+ filter_name = model ? "#{model.table_name}.#{name}" : name
66
+ @grid.filter_params.key?(filter_name) ? @grid.filter_params[filter_name] : nil
67
+ end
68
68
 
69
- def get_filter_id(name: nil, model: nil)
70
- @grid.get_filter_name(name, model).parameterize('_')
71
- end
69
+ def get_filter_id(name: nil, model: nil)
70
+ @grid.get_filter_name(name, model).parameterize('_')
71
+ end
72
72
 
73
- def filter_options(name, options, with_id = true)
74
- opts = {name: name}
75
- if options.is_a?(Hash) && options.has_key?(:model)
76
- model = options.delete(:model)
77
- raise MightyGridArgumentError.new("Model of field for filtering should have type ActiveRecord") if model.present? && model.superclass != ActiveRecord::Base
78
- opts.merge!(model: model)
79
- options.merge!(id: get_filter_id(opts)) if with_id
80
- end
81
- opts
73
+ def filter_options(name, options, with_id = true)
74
+ opts = { name: name }
75
+ if options.is_a?(Hash) && options.key?(:model)
76
+ model = options.delete(:model)
77
+ fail MightyGridArgumentError.new('Model of field for filtering should have type ActiveRecord') if model.present? && model.superclass != ActiveRecord::Base
78
+ opts.merge!(model: model)
79
+ options.merge!(id: get_filter_id(opts)) if with_id
82
80
  end
81
+ opts
82
+ end
83
83
  end
84
- end
84
+ end