actionset 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ee586ba731ff0d62c70c6417a6a66e439118ed2
4
- data.tar.gz: f9db7e51b54c2865171d2b4bf34751565e602616
3
+ metadata.gz: c871a0d14017c94fcf75a2b748c17ecba1ab1012
4
+ data.tar.gz: fcd8576591a6411bd53f43077041eb06b170f56b
5
5
  SHA512:
6
- metadata.gz: ca9fc3e8a5446736ecce76e39b5d16bda747f231760fbc25ed644ca55a5c60895844a50cddbca18befe9cbd0c4a190bcb7b7cc93d5d01adaf3767e0b4d9bf530
7
- data.tar.gz: 545317adeca664239fdbcfb9413d4dcd9a3c7d4b1a08dd0b1ae50a982d75be32a29ebda542ea01f208343ff440797e3caf4c2fbf6e652e3986842cb08df48d35
6
+ metadata.gz: 23c0be2f1fa6591a5eb329192b0fa33a5d40677bcdb58ec3e686441da8992da6962b56d8a9a9c96ec694f894b7dd7c268effe446c95275653103e8aa2afb6e92
7
+ data.tar.gz: b41fc568c512ee54557a1b0ee1551a988bfcab9e27c19e01c2124ec36a4b82587ddb832afeefc66ee4b5694ef636622d2218d3c9c2ce9b406b1220ae403f1920
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v 0.2.0
2
+ - Add a new `export_set` method
3
+ This allows datasets to be transformed into CSV and exported
4
+ - Create distinct controller methods for filtering and sorting, not just the one 'process_set' method
1
5
  v 0.1.3
2
6
  - Ensure that the ActiveModelAdapter for the typcastor properly downgrades from using ActiveModel::Type to using ActiveRecord::Type
3
7
  - Ensure that OpenStuct is explicly required
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'activeset', '~> 0.4.0'
25
+ spec.add_dependency 'activeset', '>= 0.5.1'
26
26
  spec.add_dependency 'activesupport', '>= 4.0.2'
27
27
  spec.add_dependency 'railties'
28
28
 
@@ -30,14 +30,30 @@ module ActionSet
30
30
  module InstanceMethods
31
31
  def process_set(set)
32
32
  @set = set
33
+ sort_set(filter_set(ActiveSet.new(set)))
34
+ end
35
+
36
+ def filter_set(set)
33
37
  @filters = JSON.parse(filter_params.to_json,
34
38
  object_class: Filter)
35
- active_set = ActiveSet.new(set)
39
+ active_set = set.is_a?(ActiveSet) ? set : ActiveSet.new(set)
36
40
  active_set = active_set.filter(filter_structure) if filter_params.any?
41
+ active_set
42
+ end
43
+
44
+ def sort_set(set)
45
+ active_set = set.is_a?(ActiveSet) ? set : ActiveSet.new(set)
37
46
  active_set = active_set.sort(sort_params) if sort_params.any?
38
47
  active_set
39
48
  end
40
49
 
50
+ def export_set(set)
51
+ return send_file(set, export_set_options(request.format)) if set.is_a?(String) && File.file?(set)
52
+ active_set = set.is_a?(ActiveSet) ? set : ActiveSet.new(set)
53
+ transformed_data = active_set.transform(transform_structure)
54
+ send_data(transformed_data, export_set_options(request.format))
55
+ end
56
+
41
57
  private
42
58
 
43
59
  def filter_params
@@ -55,9 +71,36 @@ module ActionSet
55
71
  end
56
72
  end
57
73
 
74
+ def transform_structure
75
+ {}.tap do |struct|
76
+ struct[:format] = transform_params[:format] || request.format.symbol
77
+ columns_params = transform_params[:columns]&.map do |column|
78
+ Hash[column&.map do |k, v|
79
+ is_literal_value = ->(key) { key.to_s == 'value*' }
80
+ key = is_literal_value.(k) ? 'value' : k
81
+ val = is_literal_value.(k) ? send(v) : v
82
+ [key, val]
83
+ end]
84
+ end
85
+ struct[:columns] = columns_params || send(:export_set_columns) || []
86
+ end
87
+ end
88
+
58
89
  def sort_params
59
90
  params.fetch(:sort, {}).to_unsafe_hash
60
91
  end
92
+
93
+ def transform_params
94
+ params.fetch(:transform, {}).to_unsafe_hash
95
+ end
96
+
97
+ def export_set_options(format)
98
+ {}.tap do |opts|
99
+ opts[:type] = format.to_s
100
+ opts[:filename] = "#{Time.zone.now.strftime('%Y%m%d_%H:%M:%S')}.#{format.symbol}"
101
+ opts[:disposition] = :inline if %w[development test].include?(Rails.env.to_s)
102
+ end
103
+ end
61
104
  end
62
105
 
63
106
  def self.included(receiver)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionSet
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2017-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeset
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 0.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.0
26
+ version: 0.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement