From 74c00b5054ef96ced7bd55753015164f6aaf13ab Mon Sep 17 00:00:00 2001 From: Noel Peden Date: Wed, 9 Apr 2014 14:20:10 -0700 Subject: [PATCH 1/2] Support Rails 4 --- .gitignore | 1 + .travis.yml | 2 +- acts_as_xlsx.gemspec | 4 ++++ lib/acts_as_xlsx/ar.rb | 6 +++++- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68feb7d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Gemfile.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index b78f7c3..f1ebb33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ rvm: - 1.9.3 notifications: - irc: "irc.freenode.org#axlsx + irc: "irc.freenode.org#axlsx" diff --git a/acts_as_xlsx.gemspec b/acts_as_xlsx.gemspec index c606276..f691ff1 100644 --- a/acts_as_xlsx.gemspec +++ b/acts_as_xlsx.gemspec @@ -21,6 +21,10 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'activerecord', '>= 2.3.9' s.add_runtime_dependency 'i18n', '>= 0.4.1' + if RUBY_VERSION == "2.0.0" + s.add_development_dependency 'rake' + s.add_development_dependency 'minitest' + end s.add_development_dependency 'rake', "0.8.7" if RUBY_VERSION == "1.9.2" s.add_development_dependency 'rake', "~> 0.9" if ["1.9.3", "1.8.7"].include?(RUBY_VERSION) s.add_development_dependency 'bundler' diff --git a/lib/acts_as_xlsx/ar.rb b/lib/acts_as_xlsx/ar.rb index 595bd56..8e8ba0a 100644 --- a/lib/acts_as_xlsx/ar.rb +++ b/lib/acts_as_xlsx/ar.rb @@ -62,7 +62,11 @@ def to_xlsx(options = {}) header_style = p.workbook.styles.add_style(header_style) unless header_style.nil? i18n = self.xlsx_i18n == true ? 'activerecord.attributes' : i18n sheet_name = options.delete(:name) || (i18n ? I18n.t("#{i18n}.#{table_name.underscore}") : table_name.humanize) - data = options.delete(:data) || [*find(:all, options)] + if Rails.version[0] >= '4' + data = options.delete(:data) || where(options[:where]).order(options[:order]).to_a + else + data = options.delete(:data) || [*find(:all, options)] + end data.compact! data.flatten! From b9c431820a7f65957e65cfad088e512814f01522 Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Tue, 24 Mar 2015 14:42:07 -0700 Subject: [PATCH 2/2] add support for nil values --- lib/acts_as_xlsx/ar.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/acts_as_xlsx/ar.rb b/lib/acts_as_xlsx/ar.rb index 8e8ba0a..89bc7d9 100644 --- a/lib/acts_as_xlsx/ar.rb +++ b/lib/acts_as_xlsx/ar.rb @@ -84,7 +84,7 @@ def to_xlsx(options = {}) data.each do |r| row_data = columns.map do |c| if c.to_s =~ /\./ - v = r; c.to_s.split('.').each { |method| v = v.send(method) }; v + v = r; c.to_s.split('.').each { |method| !v.nil? ? v = v.send(method) : v = ""; }; v else r.send(c) end