rexport 0.5.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +6 -34
  3. data/app/views/export_filters/_export_filter.html.erb +2 -2
  4. data/app/views/export_items/_export_item.html.erb +2 -2
  5. data/app/views/exports/_edit.html.erb +2 -2
  6. data/app/views/exports/_filters.html.erb +1 -1
  7. data/app/views/exports/_form.html.erb +6 -6
  8. data/app/views/exports/_rexport_model.html.erb +1 -1
  9. data/app/views/exports/_show.html.erb +6 -6
  10. data/app/views/exports/edit.html.erb +1 -1
  11. data/app/views/exports/index.html.erb +5 -5
  12. data/app/views/exports/new.html.erb +2 -2
  13. data/app/views/exports/show.html.erb +1 -1
  14. data/config/routes.rb +6 -6
  15. data/db/migrate/20091105182959_create_export_tables.rb +3 -3
  16. data/lib/rexport.rb +3 -1
  17. data/lib/rexport/data_field.rb +17 -0
  18. data/lib/rexport/data_fields.rb +25 -56
  19. data/lib/rexport/export_filter_methods.rb +46 -24
  20. data/lib/rexport/export_item_methods.rb +29 -34
  21. data/lib/rexport/export_methods.rb +161 -208
  22. data/lib/rexport/exports_controller_methods.rb +22 -28
  23. data/lib/rexport/rexport_model.rb +33 -0
  24. data/lib/rexport/tree_node.rb +13 -16
  25. data/lib/rexport/version.rb +1 -1
  26. data/test/factories.rb +58 -53
  27. data/test/test_helper.rb +29 -33
  28. data/test/unit/data_field_test.rb +11 -11
  29. data/test/unit/data_fields_test.rb +137 -95
  30. data/test/unit/export_filter_methods_test.rb +37 -0
  31. data/test/unit/export_item_methods_test.rb +21 -0
  32. data/test/unit/export_methods_test.rb +185 -59
  33. data/test/unit/rexport_model_test.rb +12 -12
  34. data/test/unit/tree_node_test.rb +20 -20
  35. metadata +14 -26
  36. data/test/jenkins.bash +0 -3
  37. data/test/log/test.log +0 -3891
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c1feb585dc87a52250b3856dfb0431730f5c2cc0
4
- data.tar.gz: 7f4eb61376b04dd6fd2206535421d8c155e76091
2
+ SHA256:
3
+ metadata.gz: 2d78c303332bc96efaf4f0a9548db0a0604250e48089e512cc7d106853c47efb
4
+ data.tar.gz: 32469341766f9e0a262ce8d16fb0872172d0190f9b03c0023af81ecf7f2cd5f8
5
5
  SHA512:
6
- metadata.gz: d19ae468e08d54cf89046c1e685fc819b7282ca316312fdd52fca7a5d3e4891c0389a2685381fa6dc07e0c4041c2128ed1133e3141c8e25f819a5992de1bbc5d
7
- data.tar.gz: 915035b53f2ae3c990a41534f8661ce896bcad70509ac79892a1bb07eb808dba6d62256a488b949803e8ed3117833526ea2cdee5a6221f495b77161c9c868b20
6
+ metadata.gz: 4bb5f6249a4cb8903d7c2b713c9857da2b959094879c9f7ba1acbd92130c37ff073de275d7fc36841c44adab534917b87c2c6246fa055b57f334d025b784e264
7
+ data.tar.gz: 18f5b364174c6f3b0f24b50f82b7a9a39484d2e0147437eec923a25074442c6dd7d45dd082832fb6fd731a459610a27710852551183a9c036e7f546332d48a67
data/Rakefile CHANGED
@@ -1,38 +1,10 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Rexport'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
-
24
-
25
-
26
- Bundler::GemHelper.install_tasks
27
-
28
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
29
3
 
30
4
  Rake::TestTask.new(:test) do |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
33
- t.pattern = 'test/**/*_test.rb'
34
- t.verbose = false
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
35
8
  end
36
9
 
37
-
38
- task :default => :test
10
+ task default: :test
@@ -2,6 +2,6 @@
2
2
  <td class="row_title"><%= export_filter.filter_field %></td>
3
3
  <td><%= export_filter.display_value %></td>
4
4
  <td class="table_icons">
5
- <%= link_to_delete(export_filter, :text => false) %>
5
+ <%= link_to_delete(export_filter, text: false) %>
6
6
  </td>
7
- </tr>
7
+ </tr>
@@ -3,6 +3,6 @@
3
3
  <td><%= export_item.rexport_field %></td>
4
4
  <td class="table_icons">
5
5
  <%= link_to(image_tag('icon_edit.gif'), edit_export_item_path(export_item)) if @export.modifiable? %>
6
- <%= link_to_delete(export_item, :text => false) if @export.modifiable? %>
6
+ <%= link_to_delete(export_item, text: false) if @export.modifiable? %>
7
7
  </td>
8
- </tr>
8
+ </tr>
@@ -1,7 +1,7 @@
1
1
  <h1>Edit Export</h1>
2
2
 
3
- <%= render :partial => 'form' %>
3
+ <%= render partial: 'form' %>
4
4
 
5
5
  <p>
6
6
  <%= link_to_cancel @export %>
7
- </p>
7
+ </p>
@@ -5,5 +5,5 @@
5
5
  <th>Value</th>
6
6
  <th class='action_icons'>&nbsp;</th>
7
7
  </tr>
8
- <%= render :partial => @export.export_filters %>
8
+ <%= render partial: @export.export_filters %>
9
9
  </table>
@@ -1,7 +1,7 @@
1
1
  <div id="rexport">
2
2
  <%= form_for(@export) do |f| %>
3
3
  <%= f.error_messages %>
4
-
4
+
5
5
  <div class="export_base_info">
6
6
  <%= f.label :name %>
7
7
  <%= f.text_field :name %>
@@ -11,13 +11,13 @@
11
11
  <%= f.text_area :description %>
12
12
  </div>
13
13
 
14
- <%= render :partial => 'local_form', :locals => { :form => f } %>
15
-
14
+ <%= render partial: 'local_form', locals: { form: f } %>
15
+
16
16
  <h3>Export Items</h3>
17
- <%= render :partial => 'rexport_model', :collection => @export.rexport_models %>
18
-
17
+ <%= render partial: 'rexport_model', collection: @export.rexport_models %>
18
+
19
19
  <%= f.hidden_field :model_class_name %>
20
-
20
+
21
21
  <div>
22
22
  <%= f.submit 'Save Export' %>
23
23
  </div>
@@ -14,4 +14,4 @@
14
14
  </td>
15
15
  </tr>
16
16
  <% end %>
17
- </table>
17
+ </table>
@@ -3,8 +3,8 @@
3
3
  <h4>Options</h4>
4
4
  <ul>
5
5
  <li><%= link_to("#{image_tag('icon_edit.gif')} Edit".html_safe, edit_export_path(@export)) if @export.modifiable? %></li>
6
- <li><%= link_to "#{image_tag('icon_export.png')} Export".html_safe, export_path(@export, :format => :csv) %></li>
7
- <li><%= link_to "#{image_tag('icon_copy.png')} Copy".html_safe, exports_path(:original_export_id => @export.id), :method => :post %></li>
6
+ <li><%= link_to "#{image_tag('icon_export.png')} Export".html_safe, export_path(@export, format: :csv) %></li>
7
+ <li><%= link_to "#{image_tag('icon_copy.png')} Copy".html_safe, exports_path(:original_export_id => @export.id), method: :post %></li>
8
8
  </ul>
9
9
  </div>
10
10
  <div class="show_export_info">
@@ -29,14 +29,14 @@
29
29
  <th class='action_icons'>&nbsp;</th>
30
30
  </tr>
31
31
  </thead>
32
- <%= content_tag :tbody, {:id => 'export_items'}.merge(@export.modifiable? ? {:class => 'sortable', 'data-url' => export_item_sorting_path} : {}) do %>
33
- <%= render :partial => @export.export_items.ordered %>
32
+ <%= content_tag :tbody, {id: 'export_items'}.merge(@export.modifiable? ? {class: 'sortable', 'data-url' => export_item_sorting_path} : {}) do %>
33
+ <%= render partial: @export.export_items.ordered %>
34
34
  <% end %>
35
35
  </table>
36
36
 
37
- <%= content_tag(:p, 'Drag and drop the rows in the table above to re-order the export data left to right in the output (see sample below).', :class => 'instructions') if @export.modifiable? %>
37
+ <%= content_tag(:p, 'Drag and drop the rows in the table above to re-order the export data left to right in the output (see sample below).', class: 'instructions') if @export.modifiable? %>
38
38
 
39
- <%= render(:partial => 'filters') unless @export.export_filters.blank? %>
39
+ <%= render(partial: 'filters') unless @export.export_filters.blank? %>
40
40
 
41
41
  <div class='scrolling'>
42
42
  <table>
@@ -1 +1 @@
1
- <%= render :partial => 'edit' %>
1
+ <%= render partial: 'edit' %>
@@ -1,4 +1,4 @@
1
- <%= form_for Export.new, :url => new_export_path, :html => {:method => :get} do |f| %>
1
+ <%= form_for Export.new, url: new_export_path, html: {method: :get} do |f| %>
2
2
  <fieldset>
3
3
  <legend>Create New Export</legend>
4
4
  <div class='dropdown'>
@@ -23,10 +23,10 @@
23
23
  <td class='description'><%= export.description %></td>
24
24
  <td><%= print_date export.created_at %></td>
25
25
  <td class="table_icons">
26
- <%= link_to_export export_path(export, :format => :csv), :text => false %>
27
- <%= link_to_show export, :text => false %>
28
- <%= link_to(image_tag('icon_edit.gif'), edit_export_path(export), :title => 'Edit') if export.modifiable? %>
29
- <%= link_to_delete(export, :text => false) if export.modifiable? %>
26
+ <%= link_to_export export_path(export, format: :csv), text: false %>
27
+ <%= link_to_show export, text: false %>
28
+ <%= link_to(image_tag('icon_edit.gif'), edit_export_path(export), title: 'Edit') if export.modifiable? %>
29
+ <%= link_to_delete(export, text: false) if export.modifiable? %>
30
30
  </td>
31
31
  </tr>
32
32
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <h1>New <%= @export.model_class_name %> Export</h1>
2
2
 
3
- <%= render :partial => 'form' %>
3
+ <%= render partial: 'form' %>
4
4
 
5
5
  <div>
6
6
  <%= link_to_cancel exports_path %>
7
- </div>
7
+ </div>
@@ -1 +1 @@
1
- <%= render :partial => 'show' %>
1
+ <%= render partial: 'show' %>
@@ -1,11 +1,11 @@
1
1
  Rails.application.routes.draw do
2
2
  # singleton resources
3
- resource :export_item_sorting, :only => [:update]
4
-
3
+ resource :export_item_sorting, only: :update
4
+
5
5
  # collection resources
6
- resources :export_items, :only => [:edit, :update, :destroy]
7
- resources :export_filters, :only => [:edit, :update, :destroy]
6
+ resources :export_items, only: %i(edit update destroy)
7
+ resources :export_filters, only: %i(edit update destroy)
8
8
  resources :exports do
9
- resources :export_filters, :only => [:new]
9
+ resources :export_filters, only: :new
10
10
  end
11
- end
11
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateExportTables < ActiveRecord::Migration
2
2
  def self.up
3
- create_table "export_filters", :force => true do |t|
3
+ create_table "export_filters", force: true do |t|
4
4
  t.integer "export_id"
5
5
  t.string "field"
6
6
  t.string "value"
@@ -8,7 +8,7 @@ class CreateExportTables < ActiveRecord::Migration
8
8
  t.datetime "updated_at"
9
9
  end
10
10
 
11
- create_table "export_items", :force => true do |t|
11
+ create_table "export_items", force: true do |t|
12
12
  t.integer "export_id"
13
13
  t.integer "position"
14
14
  t.string "name"
@@ -17,7 +17,7 @@ class CreateExportTables < ActiveRecord::Migration
17
17
  t.datetime "updated_at"
18
18
  end
19
19
 
20
- create_table "exports", :force => true do |t|
20
+ create_table "exports", force: true do |t|
21
21
  t.string "name"
22
22
  t.string "model_class_name"
23
23
  t.text "description"
@@ -1,3 +1,4 @@
1
+ require 'rexport/data_field'
1
2
  require 'rexport/data_fields'
2
3
  require 'rexport/export_filter_methods'
3
4
  require 'rexport/export_filters_controller_methods'
@@ -6,12 +7,13 @@ require 'rexport/export_item_sortings_controller_methods'
6
7
  require 'rexport/export_items_controller_methods'
7
8
  require 'rexport/export_methods'
8
9
  require 'rexport/exports_controller_methods'
10
+ require 'rexport/rexport_model'
9
11
  require 'rexport/tree_node'
10
12
 
11
13
  module Rexport
14
+ SAMPLE_SIZE = 5
12
15
 
13
16
  class Engine < ::Rails::Engine
14
17
  config.paths['app/views'] << File.join(File.dirname(__FILE__),'../app/views')
15
18
  end
16
-
17
19
  end
@@ -0,0 +1,17 @@
1
+ module Rexport
2
+ class DataField
3
+ include Comparable
4
+ attr_accessor :name, :method, :type
5
+
6
+ # Stores the name and method of the export data item
7
+ def initialize(name, options = {})
8
+ self.name = name.to_s
9
+ self.method = options[:method].blank? ? self.name : options[:method].to_s
10
+ self.type = options[:type]
11
+ end
12
+
13
+ def <=>(rf)
14
+ self.name <=> rf.name
15
+ end
16
+ end
17
+ end
@@ -1,33 +1,11 @@
1
1
  module Rexport #:nodoc:
2
-
3
- # Stores the name and method of the export data item
4
- class DataField
5
- include Comparable
6
- attr_accessor :name, :method, :type
7
-
8
- def initialize(name, options = {})
9
- self.name = name.to_s
10
- self.method = options[:method].blank? ? self.name : options[:method].to_s
11
- self.type = options[:type]
12
- end
13
-
14
- def <=>(rf)
15
- self.name <=> rf.name
16
- end
17
- end
18
-
19
2
  module DataFields
20
- def self.included( base )
21
- base.extend( ClassMethods )
22
- base.class_eval do
23
- include InstanceMethods
24
- prepend ClassMethods
25
- end
26
- end
3
+ extend ActiveSupport::Concern
27
4
 
28
5
  module ClassMethods
29
6
  # Returns hash of exportable data items
30
7
  def rexport_fields
8
+ @rexport_fields ||= nil
31
9
  unless @rexport_fields
32
10
  @rexport_fields = HashWithIndifferentAccess.new
33
11
  initialize_rexport_fields
@@ -37,7 +15,7 @@ module Rexport #:nodoc:
37
15
 
38
16
  # Returns sorted array of rexport DataFields
39
17
  def rexport_fields_array
40
- rexport_fields.merge(dynamic_rexport_fields).values.sort
18
+ rexport_fields.values.sort
41
19
  end
42
20
 
43
21
  # Adds a data item to rexport_fields
@@ -48,7 +26,7 @@ module Rexport #:nodoc:
48
26
  # Adds associated methods to rexport_fields
49
27
  # :associations - an association or arrary of associations
50
28
  # :methods - a method or array of methods
51
- # :filter - if true will send :type => :association to add_report_field
29
+ # :filter - if true will send type: :association to add_report_field
52
30
  def add_association_methods(options = {})
53
31
  options.stringify_keys!
54
32
  options.assert_valid_keys(%w(associations methods filter))
@@ -63,7 +41,7 @@ module Rexport #:nodoc:
63
41
 
64
42
  associations.each do |association|
65
43
  methods.each do |method|
66
- add_rexport_field("#{association}_#{method}", :method => "#{association}.#{method}", :type => type)
44
+ add_rexport_field("#{association}_#{method}", method: "#{association}.#{method}", type: type)
67
45
  end
68
46
  end
69
47
  end
@@ -71,7 +49,7 @@ module Rexport #:nodoc:
71
49
  # Removes files from rexport_fields
72
50
  # useful to remove content columns you don't want included in exports
73
51
  def remove_rexport_fields(*fields)
74
- fields.flatten.each {|field| rexport_fields.delete(field.to_s)}
52
+ fields.flatten.each { |field| rexport_fields.delete(field.to_s) }
75
53
  end
76
54
 
77
55
  # Returns an array of export methods corresponding with field_names
@@ -96,11 +74,10 @@ module Rexport #:nodoc:
96
74
 
97
75
  # Returns the export method for a given field_name
98
76
  def get_rexport_method(field_name)
99
- raise NoMethodError unless rexport_fields[field_name] or dynamic_rexport_fields[field_name]
100
77
  if rexport_fields[field_name]
101
78
  rexport_fields[field_name].method
102
79
  else
103
- dynamic_rexport_fields[field_name].method
80
+ raise NoMethodError
104
81
  end
105
82
  end
106
83
 
@@ -111,40 +88,32 @@ module Rexport #:nodoc:
111
88
 
112
89
  private
113
90
 
114
- # Adds content columns and columns ending in "_count" to rexport_fields, includes callback initialize_local_rexport_fields
115
- # for client defined initialization
91
+ # Adds content columns rexport_fields, includes callback
92
+ # initialize_local_rexport_fields for client defined initialization
116
93
  def initialize_rexport_fields
117
- (content_columns + columns.select {|c| c.name =~ /_count$/}).each do |f|
118
- add_rexport_field(f.name, :type => f.type)
119
- end
94
+ content_columns.each { |field| add_rexport_field(field.name, type: field.type) }
120
95
  initialize_local_rexport_fields if respond_to?(:initialize_local_rexport_fields)
121
96
  end
122
-
123
- def dynamic_rexport_fields
124
- respond_to?(:initialize_dynamic_rexport_fields) ? initialize_dynamic_rexport_fields : {}
125
- end
126
97
  end
127
98
 
128
- module InstanceMethods
129
- # Return an array of formatted export for the passed methods
130
- def export(*methods)
131
- methods.flatten.map do |method|
132
- case value = (eval("self.#{method}", binding) rescue nil)
133
- when Date, Time
134
- value.strftime("%m/%d/%y")
135
- when TrueClass
136
- 'Y'
137
- when FalseClass
138
- 'N'
139
- else value.to_s
140
- end
99
+ # Return an array of formatted export values for the passed methods
100
+ def export(*methods)
101
+ methods.flatten.map do |method|
102
+ case value = (eval("self.#{method}", binding) rescue nil)
103
+ when Date, Time
104
+ value.strftime("%m/%d/%y")
105
+ when TrueClass
106
+ 'Y'
107
+ when FalseClass
108
+ 'N'
109
+ else value.to_s
141
110
  end
142
111
  end
112
+ end
143
113
 
144
- # Returns string indicating this field is undefined
145
- def undefined_rexport_field
146
- 'UNDEFINED EXPORT FIELD'
147
- end
114
+ # Returns string indicating this field is undefined
115
+ def undefined_rexport_field
116
+ 'UNDEFINED EXPORT FIELD'
148
117
  end
149
118
  end
150
119
  end
@@ -1,34 +1,56 @@
1
1
  module Rexport #:nodoc:
2
2
  module ExportFilterMethods
3
- def self.included(base)
4
- base.class_eval do
5
- include InstanceMethods
3
+ extend ActiveSupport::Concern
6
4
 
7
- belongs_to :export
8
- validates_presence_of :filter_field
9
- end
5
+ included do
6
+ belongs_to :export
7
+ validates_presence_of :filter_field
8
+ end
9
+
10
+ def display_value
11
+ filter_on_associated_object? ? associated_object_value : value
12
+ end
13
+
14
+ def attributes_for_copy
15
+ attributes.slice('filter_field', 'value')
10
16
  end
11
17
 
12
- module InstanceMethods
13
- def display_value
14
- return value unless filter_field[/_id$/]
15
- path = filter_field.split('.')
16
- foreign_key = path.pop
17
- association = export.get_klass_from_path(path).reflect_on_all_associations(:belongs_to).detect do |association|
18
- association.foreign_key == foreign_key
19
- end
20
- return 'UNDEFINED ASSOCIATION' unless association
21
- begin
22
- object = association.klass.find(value)
23
- return object.respond_to?(:name) ? object.name : object.to_s
24
- rescue ActiveRecord::RecordNotFound
25
- return 'ASSOCIATED OBJECT NOT FOUND'
26
- end
18
+ private
19
+
20
+ def associated_object_value
21
+ return 'UNDEFINED ASSOCIATION' unless filter_association
22
+ begin
23
+ object = filter_association.klass.find(value)
24
+ return object.respond_to?(:name) ? object.name : object.to_s
25
+ rescue ActiveRecord::RecordNotFound
26
+ return 'ASSOCIATED OBJECT NOT FOUND'
27
27
  end
28
-
29
- def attributes_for_copy
30
- attributes.slice('filter_field', 'value')
28
+ end
29
+
30
+ def filter_association
31
+ @filter_on_assocation ||= find_filter_association
32
+ end
33
+
34
+ def find_filter_association
35
+ belongs_to_associations.detect do |association|
36
+ association.foreign_key == filter_foreign_key
31
37
  end
32
38
  end
39
+
40
+ def belongs_to_associations
41
+ export.get_klass_from_path(filter_path).reflect_on_all_associations(:belongs_to)
42
+ end
43
+
44
+ def filter_path
45
+ filter_field.split('.')[0..-2]
46
+ end
47
+
48
+ def filter_foreign_key
49
+ filter_field.split('.').last
50
+ end
51
+
52
+ def filter_on_associated_object?
53
+ filter_field[/_id$/]
54
+ end
33
55
  end
34
56
  end