active_report 3.0.0 → 4.0.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: 845701856d05d78aead835a3450a3b383c3f56ff
4
- data.tar.gz: 877307c33e0d935f83d8f9f48432bdec40f54602
3
+ metadata.gz: 7a7721137489f45557408d7a01b7a8ec390844cb
4
+ data.tar.gz: 10b0150bb46e4657b5805ea23e710d66061c9df4
5
5
  SHA512:
6
- metadata.gz: e1c40b631709dec74fcd328736008e27ac2cba979d19ff868fe9381647ca636b06ee36dce81b4adf9b924049df52f103e6533cc94bebc41904a22c9b06a99ea6
7
- data.tar.gz: 5f956e8f055abed5d1666c7a062fd87e43e96805e373d693b99d02a69b945a662adfae786263b8fcf983edf5998b151789910373560ef85655c24fe33a6be67a
6
+ metadata.gz: e5df1dae98cae8119165870506c10f525408545cac9f66aed8566caac3ca2dbe199105fc065d1091578950824370d2057eff596f25bcd921caf4ec53b552a6ec
7
+ data.tar.gz: 03fb99c2bf92603f85297b21f3174bc41aec58b7a75994927f0eec0d5c276b6bfd662b707cf64861403346984ac33b850511b230c9539852cb0644c645db8539
data/.DS_Store ADDED
Binary file
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.reek ADDED
@@ -0,0 +1,42 @@
1
+ ---
2
+ Attribute:
3
+ enabled: false
4
+ BooleanParameter:
5
+ enabled: false
6
+ ClassVariable:
7
+ enabled: false
8
+ ControlParameter:
9
+ enabled: false
10
+ DuplicateMethodCall:
11
+ enabled: false
12
+ FeatureEnvy:
13
+ enabled: false
14
+ IrresponsibleModule:
15
+ enabled: false
16
+ InstanceVariableAssumption:
17
+ enabled: false
18
+ LongParameterList:
19
+ enabled: false
20
+ ManualDispatch:
21
+ enabled: false
22
+ NestedIterators:
23
+ max_allowed_nesting: 2
24
+ NilCheck:
25
+ enabled: false
26
+ PrimaDonnaMethod:
27
+ enabled: false
28
+ RepeatedConditional:
29
+ enabled: false
30
+ TooManyInstanceVariables:
31
+ enabled: false
32
+ TooManyStatements:
33
+ max_statements: 10
34
+ exclude:
35
+ - 'ActiveReport::Base#metamorph'
36
+ - 'ActiveReport::Hash#import'
37
+ - 'ActiveReport::Record#import'
38
+ UncommunicativeMethodName:
39
+ exclude:
40
+ - 'ActiveReport::Base#encode_to_utf8'
41
+ UtilityFunction:
42
+ enabled: false
data/.rubocop.yml ADDED
@@ -0,0 +1,48 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.3
5
+ Exclude:
6
+ - 'spec/**/**/*'
7
+ LineLength:
8
+ Max: 100
9
+ Metrics/AbcSize:
10
+ Enabled: false
11
+ Metrics/ClassLength:
12
+ Enabled: false
13
+ Metrics/MethodLength:
14
+ Enabled: false
15
+ Metrics/ModuleLength:
16
+ Enabled: false
17
+ Metrics/ParameterLists:
18
+ Enabled: false
19
+ Style/Alias:
20
+ EnforcedStyle: prefer_alias_method
21
+ Style/BracesAroundHashParameters:
22
+ Enabled: false
23
+ Style/ClassAndModuleChildren:
24
+ EnforcedStyle: compact
25
+ Style/ClassVars:
26
+ Enabled: false
27
+ Style/ClosingParenthesisIndentation:
28
+ Enabled: false
29
+ Style/Documentation:
30
+ Enabled: false
31
+ Style/EmptyLinesAroundBlockBody:
32
+ Enabled: false
33
+ Style/EmptyLinesAroundClassBody:
34
+ Enabled: false
35
+ Style/EmptyLinesAroundModuleBody:
36
+ Enabled: false
37
+ Style/HashSyntax:
38
+ Enabled: false
39
+ Style/FirstParameterIndentation:
40
+ Enabled: false
41
+ Style/FrozenStringLiteralComment:
42
+ Enabled: false
43
+ Style/MultilineMethodCallIndentation:
44
+ EnforcedStyle: aligned
45
+ Style/NumericLiterals:
46
+ Enabled: false
47
+ Style/RescueModifier:
48
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Specify your gem"s dependencies in active_report.gemspec
3
+ # Specify your gem's dependencies in active_report.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -11,7 +11,7 @@ ActiveReport is a library to export CSV's out of arrays, hashes, and records and
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem "active_report"
14
+ gem 'active_report'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -32,16 +32,13 @@ Or install it yourself as:
32
32
 
33
33
  ## Configuration
34
34
 
35
- `rails g active_report:install` will generate the following `active_report.rb` file:
35
+ `rails g active_report:install` will generate the following file:
36
+ `../config/initalizers/active_report.rb`
36
37
 
37
38
  ```ruby
38
- # config/initalizers/active_report.rb
39
-
40
- ActiveReport.configure do |config|
41
- # option = default
42
-
39
+ ActiveReport::Settings.configure do |config|
43
40
  config.force_encoding = true
44
- config.options = { encoding: "UTF-8" }
41
+ config.options = { encoding: 'UTF-8' }
45
42
  end
46
43
  ```
47
44
 
@@ -55,13 +52,13 @@ end
55
52
 
56
53
  ```ruby
57
54
  @list = [
58
- [1, "Lorem lipsum etc...", true],
59
- [2, "Xorem lipsum etc...", false],
60
- [3, "Porem lipsum etc...", true]
55
+ [1, 'Lorem lipsum etc...', true],
56
+ [2, 'Xorem lipsum etc...', false],
57
+ [3, 'Porem lipsum etc...', true]
61
58
  ]
62
59
 
63
60
  ActiveReport::Array.export(@list)
64
- ActiveReport::Array.export(@list, headers: ["ID", "Task", "Completed"], options: { col_sep: ";" })
61
+ ActiveReport::Array.export(@list, headers: ['ID', 'Task', 'Completed'], options: { col_sep: ';' })
65
62
  ```
66
63
 
67
64
  **Import:** Convert a CSV into an array or array of arrays.
@@ -71,8 +68,8 @@ ActiveReport::Array.export(@list, headers: ["ID", "Task", "Completed"], options:
71
68
  * options: CSV options to be use on parsing
72
69
 
73
70
  ```ruby
74
- ActiveReport::Array.import("sample.csv")
75
- ActiveReport::Array.import("sample.csv", headers: ["ID", "Task", "Completed"], options: { col_sep: ";" })
71
+ ActiveReport::Array.import('sample.csv')
72
+ ActiveReport::Array.import('sample.csv', headers: ['ID', 'Task', 'Completed'], options: { col_sep: ';' })
76
73
  ```
77
74
 
78
75
  ## Hash
@@ -87,13 +84,13 @@ ActiveReport::Array.import("sample.csv", headers: ["ID", "Task", "Completed"], o
87
84
 
88
85
  ```ruby
89
86
  @list = [
90
- { id: 1, item: "Lorem lipsum etc...", completed: true},
91
- { id: 2, item: "Xorem lipsum etc...", completed: false},
92
- { id: 3, item: "Porem lipsum etc...", completed: true}
87
+ { id: 1, item: 'Lorem lipsum etc...', completed: true},
88
+ { id: 2, item: 'Xorem lipsum etc...', completed: false},
89
+ { id: 3, item: 'Porem lipsum etc...', completed: true}
93
90
  ]
94
91
 
95
92
  ActiveReport::Hash.export(@list)
96
- ActiveReport::Hash.export(@list, only: [:id, :item], headers: ["ID", "Task"], options: { col_sep: ";" })
93
+ ActiveReport::Hash.export(@list, only: [:id, :item], headers: ['ID', 'Task'], options: { col_sep: ';' })
97
94
  ```
98
95
 
99
96
  **Import:** Convert a CSV into an array of hashes.
@@ -105,8 +102,8 @@ ActiveReport::Hash.export(@list, only: [:id, :item], headers: ["ID", "Task"], op
105
102
  * options: CSV options to be use on parsing
106
103
 
107
104
  ```ruby
108
- ActiveReport::Hash.import("sample.csv")
109
- ActiveReport::Hash.import("sample.csv", except: :completed, headers: ["ID", "Task"], options: { col_sep: ";" })
105
+ ActiveReport::Hash.import('sample.csv')
106
+ ActiveReport::Hash.import('sample.csv', except: :completed, headers: ['ID', 'Task'], options: { col_sep: ';' })
110
107
  ```
111
108
 
112
109
  ## Record
@@ -127,7 +124,7 @@ ActiveReport::Hash.import("sample.csv", except: :completed, headers: ["ID", "Tas
127
124
  ]
128
125
 
129
126
  ActiveReport::Record.export(@list)
130
- ActiveReport::Record.export(@list, only: [:id, :item], headers: ["ID", "Task"], options: { col_sep: ";" })
127
+ ActiveReport::Record.export(@list, only: [:id, :item], headers: ['ID', 'Task'], options: { col_sep: ';' })
131
128
  ```
132
129
 
133
130
  **Import:** Create new database records from a CSV.
@@ -140,8 +137,8 @@ ActiveReport::Record.export(@list, only: [:id, :item], headers: ["ID", "Task"],
140
137
  * options: CSV options to be use on parsing
141
138
 
142
139
  ```ruby
143
- ActiveReport::Record.import("sample.csv", model: User)
144
- ActiveReport::Record.import("sample.csv", model: User, except: :completed, headers: ["ID", "Task"], options: { col_sep: ";" })
140
+ ActiveReport::Record.import('sample.csv', model: User)
141
+ ActiveReport::Record.import('sample.csv', model: User, except: :completed, headers: ['ID', 'Task'], options: { col_sep: ';' })
145
142
  ```
146
143
 
147
144
  ## Evaluate
@@ -149,7 +146,7 @@ ActiveReport::Record.import("sample.csv", model: User, except: :completed, heade
149
146
  **Array/Hash:** Convert the import of a array or hash to proper ruby objects.
150
147
 
151
148
  ```ruby
152
- ActiveReport::Hash.evaluate.import("sample.csv")
149
+ ActiveReport::Hash.evaluate.import('sample.csv')
153
150
  ```
154
151
 
155
152
  ## Contributing
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  task default: :spec
@@ -1,32 +1,37 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "active_report/version"
4
+ require 'active_report/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "active_report"
7
+ spec.name = 'active_report'
8
8
  spec.version = ActiveReport::VERSION
9
- spec.authors = ["Juan Gomez"]
10
- spec.email = ["j.gomez@drexed.com"]
9
+ spec.authors = ['Juan Gomez']
10
+ spec.email = ['j.gomez@drexed.com']
11
11
 
12
- spec.summary = %q{Gem for exporting/importing ruby objects to flat files vice versa.}
13
- spec.description = %q{Export or import data from multiple input formats such as arrays, hashes, and active record or vice versa.}
14
- spec.homepage = "http://drexed.github.io/active_report"
15
- spec.license = "MIT"
12
+ spec.summary = 'Gem for exporting/importing ruby objects to flat files vice versa.'
13
+ # rubocop:disable Metrics/LineLength
14
+ spec.description = 'Export or import data from multiple input formats such as arrays, hashes, and active record or vice versa.'
15
+ # rubocop:enable Metrics/LineLength
16
+ spec.homepage = 'http://drexed.github.io/active_report'
17
+ spec.license = 'MIT'
16
18
 
17
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
20
+ spec.bindir = 'exe'
19
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
21
23
 
22
- spec.add_runtime_dependency "activerecord"
23
- spec.add_runtime_dependency "activesupport"
24
+ spec.add_runtime_dependency 'activerecord'
25
+ spec.add_runtime_dependency 'dry-configurable'
24
26
 
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "coveralls"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec"
29
- spec.add_development_dependency "sqlite3"
30
- spec.add_development_dependency "database_cleaner"
31
- spec.add_development_dependency "generator_spec"
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec'
31
+ spec.add_development_dependency 'sqlite3'
32
+ spec.add_development_dependency 'database_cleaner'
33
+ spec.add_development_dependency 'generator_spec'
34
+ spec.add_development_dependency 'fasterer'
35
+ spec.add_development_dependency 'reek'
36
+ spec.add_development_dependency 'rubocop'
32
37
  end
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "active_report"
3
+ require 'bundler/setup'
4
+ require 'active_report'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
data/bin/rake CHANGED
@@ -2,15 +2,14 @@
2
2
  #
3
3
  # This file was generated by Bundler.
4
4
  #
5
- # The application "rake" is installed as part of a gem, and
5
+ # The application 'rake' is installed as part of a gem, and
6
6
  # this file is here to facilitate running it.
7
7
  #
8
8
 
9
- require "pathname"
10
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
- Pathname.new(__FILE__).realpath)
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
12
11
 
13
- require "rubygems"
14
- require "bundler/setup"
12
+ require 'rubygems'
13
+ require 'bundler/setup'
15
14
 
16
- load Gem.bin_path("rake", "rake")
15
+ load Gem.bin_path('rake', 'rake')
@@ -3,7 +3,8 @@ class ActiveReport::Array < ActiveReport::Base
3
3
  attr_accessor :datum, :headers, :options
4
4
 
5
5
  def initialize(datum, headers: nil, options: {})
6
- @datum, @headers = datum, headers
6
+ @datum = datum
7
+ @headers = headers
7
8
  @options = duplicate_options.merge!(options)
8
9
  end
9
10
 
@@ -33,8 +34,7 @@ class ActiveReport::Array < ActiveReport::Base
33
34
  end
34
35
 
35
36
  datum = datum.flatten if datum.size < 2
36
- datum = metatransform(datum)
37
- datum
37
+ metatransform(datum)
38
38
  end
39
39
 
40
40
  end
@@ -2,7 +2,7 @@ class ActiveReport::Base
2
2
 
3
3
  @@evaluate = false
4
4
 
5
- def self.evaluate(value=true)
5
+ def self.evaluate(value = true)
6
6
  @@evaluate = value
7
7
  self
8
8
  end
@@ -10,16 +10,18 @@ class ActiveReport::Base
10
10
  private
11
11
 
12
12
  def duplicate_options
13
- ActiveReport.configuration.options.dup
13
+ ActiveReport::Settings.config.options.dup
14
14
  end
15
15
 
16
+ # rubocop:disable Performance/StringReplacement
16
17
  def encode_to_utf8(line)
17
- line.map do |l|
18
- next if l.nil?
19
- l.gsub!(/"/, "")
20
- l.encode!("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "")
18
+ line.map do |chr|
19
+ next if chr.nil?
20
+ chr.gsub!(/"/, '')
21
+ chr.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
21
22
  end
22
23
  end
24
+ # rubocop:enable Performance/StringReplacement
23
25
 
24
26
  def evaluate?
25
27
  value = @@evaluate
@@ -29,57 +31,60 @@ class ActiveReport::Base
29
31
 
30
32
  def filter(object)
31
33
  if @only.empty?
32
- object.delete_if { |key, value| @except.include?(key) } unless @except.empty?
34
+ object.delete_if { |key, _| @except.include?(key) } unless @except.empty?
33
35
  else
34
- object.keep_if { |key, value| @only.include?(key) }
36
+ object.keep_if { |key, _| @only.include?(key) }
35
37
  end
36
38
  end
37
39
 
38
40
  def filter_first(object)
39
41
  if @only.empty?
40
- object.first.delete_if { |key, value| @except.include?(key) } unless @except.empty?
42
+ object.first.delete_if { |key, _| @except.include?(key) } unless @except.empty?
41
43
  else
42
- object.first.keep_if { |key, value| @only.include?(key) }
44
+ object.first.keep_if { |key, _| @only.include?(key) }
43
45
  end
44
46
  end
45
47
 
46
48
  def force_encoding?
47
- ActiveReport.configuration.force_encoding
49
+ ActiveReport::Settings.config.force_encoding
48
50
  end
49
51
 
50
52
  def humanize(object)
51
- object.to_s.gsub("_", " ").capitalize
53
+ object.to_s.tr('_', ' ').capitalize
52
54
  end
53
55
 
54
56
  def merge(object)
55
57
  [].push(object).compact
56
58
  end
57
59
 
60
+ # rubocop:disable Lint/Eval, Lint/RescueException
58
61
  def metaform(value)
59
62
  value.nil? ? value : eval(value)
60
- rescue Exception => e
63
+ rescue Exception
61
64
  value
62
65
  end
66
+ # rubocop:enable Lint/Eval, Lint/RescueException
63
67
 
64
68
  def metamorph(datum)
65
- datum = case datum.class.name
66
- when "Array"
69
+ case datum.class.name
70
+ when 'Array'
67
71
  if datum.first.is_a?(Array)
68
- datum.map { |array| array.map { |value| metaform(value) } }
72
+ datum.map { |arr| arr.map { |val| metaform(val) } }
69
73
  elsif datum.first.is_a?(Hash)
70
- datum.map { |hash| hash.each { |key, value| hash.store(key, metaform(value)) } }
74
+ datum.map { |hsh| hsh.each { |key, val| hsh.store(key, metaform(val)) } }
71
75
  else
72
- datum.map { |value| metaform(value) }
76
+ datum.map { |val| metaform(val) }
73
77
  end
74
- when "Hash"
75
- datum.each { |key, value| datum.store(key, metaform(value)) }
78
+ when 'Hash'
79
+ datum.each { |key, val| datum.store(key, metaform(val)) }
76
80
  else
77
81
  metaform(datum)
78
82
  end
79
83
  end
80
84
 
81
85
  def metatransform(datum)
82
- datum.empty? ? nil : (evaluate? ? metamorph(datum) : datum)
86
+ return(nil) if datum.empty?
87
+ evaluate? ? metamorph(datum) : datum
83
88
  end
84
89
 
85
90
  def munge(object)
@@ -3,7 +3,10 @@ class ActiveReport::Hash < ActiveReport::Base
3
3
  attr_accessor :datum, :only, :except, :headers, :options
4
4
 
5
5
  def initialize(datum, only: nil, except: nil, headers: nil, options: {})
6
- @datum, @except, @headers, @only = datum, except, headers, only
6
+ @datum = datum
7
+ @except = except
8
+ @headers = headers
9
+ @only = only
7
10
  @options = duplicate_options.merge!(options)
8
11
  end
9
12
 
@@ -16,16 +19,19 @@ class ActiveReport::Hash < ActiveReport::Base
16
19
  end
17
20
 
18
21
  def export
19
- @datum, @only, @except = munge(@datum), munge(@only), munge(@except)
22
+ @datum = munge(@datum)
23
+ @only = munge(@only)
24
+ @except = munge(@except)
20
25
 
21
26
  CSV.generate(@options) do |csv|
22
- csv << (@headers || (filter_first(@datum) || @datum.first).keys.map { |header| humanize(header) })
27
+ csv << (@headers || (filter_first(@datum) || @datum.first).keys.map { |hdr| humanize(hdr) })
23
28
  @datum.lazy.each { |data| csv << (filter(data) || data).values }
24
29
  end
25
30
  end
26
31
 
27
32
  def import
28
- @only, @except = munge(@only), munge(@except)
33
+ @only = munge(@only)
34
+ @except = munge(@except)
29
35
 
30
36
  datum = []
31
37
  CSV.foreach(@datum, @options).with_index do |data, line|
@@ -35,8 +41,8 @@ class ActiveReport::Hash < ActiveReport::Base
35
41
  @headers = data
36
42
  else
37
43
  subdata = {}
38
- @headers.lazy.each_with_index do |header, i|
39
- subdata.store(header.to_s, data.fetch(i, nil))
44
+ @headers.lazy.each_with_index do |header, idx|
45
+ subdata.store(header.to_s, data[idx])
40
46
  end
41
47
  filter(subdata)
42
48
  datum.push(subdata)
@@ -1,10 +1,14 @@
1
- require "json"
1
+ require 'json'
2
2
  class ActiveReport::Record < ActiveReport::Base
3
3
 
4
4
  attr_accessor :datum, :model, :only, :except, :headers, :options
5
5
 
6
6
  def initialize(datum, model: nil, only: nil, except: nil, headers: nil, options: {})
7
- @datum, @except, @headers, @model, @only = datum, except, headers, model, only
7
+ @datum = datum
8
+ @except = except
9
+ @headers = headers
10
+ @model = model
11
+ @only = only
8
12
  @options = duplicate_options.merge!(options)
9
13
  end
10
14
 
@@ -17,27 +21,35 @@ class ActiveReport::Record < ActiveReport::Base
17
21
  end
18
22
 
19
23
  def export
20
- @datum = @datum.is_a?(ActiveRecord::Relation) ? JSON.parse(@datum.to_json).flatten : merge(@datum.attributes)
21
- @only, @except = munge(@only).map(&:to_s), munge(@except).map(&:to_s)
24
+ @datum = if @datum.is_a?(ActiveRecord::Relation)
25
+ JSON.parse(@datum.to_json).flatten
26
+ else
27
+ merge(@datum.attributes)
28
+ end
29
+
30
+ @only = munge(@only).map(&:to_s)
31
+ @except = munge(@except).map(&:to_s)
22
32
 
23
33
  CSV.generate(@options) do |csv|
24
- csv << (@headers || (filter_first(@datum) || @datum.first).keys.map { |header| humanize(header) })
34
+ csv << (@headers || (filter_first(@datum) || @datum.first).keys.map { |hdr| humanize(hdr) })
25
35
  @datum.lazy.each { |data| csv << (filter(data) || data).values }
26
36
  end
27
37
  end
28
38
 
29
39
  def import
30
40
  if @model.nil? || (@model.superclass != ActiveRecord::Base)
31
- raise ArgumentError, "Model must be an ActiveRecord::Base object."
41
+ raise ArgumentError, 'Model must be an ActiveRecord::Base object.'
32
42
  end
33
43
 
34
44
  @datum = ActiveReport::Hash.import(@datum, headers: @headers, options: @options)
35
- @datum, @only, @except = munge(@datum), munge(@only), munge(@except)
45
+ @datum = munge(@datum)
46
+ @only = munge(@only)
47
+ @except = munge(@except)
36
48
 
37
49
  @datum.lazy.each do |data|
38
50
  params = {}
39
51
  data.each do |key, value|
40
- key = key.to_s.downcase.gsub(" ", "_").gsub("-", "_").to_sym
52
+ key = key.to_s.downcase.tr(' ', '_').tr('-', '_').to_sym
41
53
  params.store(key, value)
42
54
  end
43
55
 
@@ -0,0 +1,9 @@
1
+ require 'dry-configurable'
2
+
3
+ class ActiveReport::Settings
4
+ extend Dry::Configurable
5
+
6
+ setting :force_encoding, true
7
+ setting :options, { encoding: 'UTF-8' }
8
+
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveReport
2
- VERSION = "3.0.0"
2
+ VERSION = '4.0.0'.freeze
3
3
  end
data/lib/active_report.rb CHANGED
@@ -1,30 +1,7 @@
1
- require "csv"
2
- require "active_report/version"
3
- require "active_report/configuration"
4
-
5
- module ActiveReport
6
-
7
- class << self
8
- attr_accessor :configuration
9
- end
10
-
11
- def self.configuration
12
- @configuration ||= Configuration.new
13
- end
14
-
15
- def self.configuration=(config)
16
- @configuration = config
17
- end
18
-
19
- def self.configure
20
- yield(configuration)
21
- end
1
+ require 'csv'
22
2
 
3
+ %w(version settings base array hash record).each do |file_name|
4
+ require "active_report/#{file_name}"
23
5
  end
24
6
 
25
- require "active_report/base"
26
- require "active_report/array"
27
- require "active_report/hash"
28
- require "active_report/record"
29
-
30
- require "generators/active_report/install_generator"
7
+ require 'generators/active_report/install_generator'
@@ -1,12 +1,10 @@
1
- require "rails/generators"
1
+ require 'rails/generators'
2
2
 
3
- module ActiveReport
4
- class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path("../templates", __FILE__)
6
-
7
- def copy_initializer_file
8
- copy_file("install.rb", "config/initializers/active_report.rb")
9
- end
3
+ class ActiveReport::InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
10
5
 
6
+ def copy_initializer_file
7
+ copy_file('install.rb', 'config/initializers/active_report.rb')
11
8
  end
9
+
12
10
  end
@@ -1,4 +1,4 @@
1
- ActiveReport.configure do |config|
1
+ ActiveReport::Settings.configure do |config|
2
2
  config.force_encoding = true
3
- config.options = { encoding: "UTF-8" }
3
+ config.options = { encoding: 'UTF-8' }
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
28
+ name: dry-configurable
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -136,6 +136,48 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fasterer
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: reek
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
139
181
  description: Export or import data from multiple input formats such as arrays, hashes,
140
182
  and active record or vice versa.
141
183
  email:
@@ -144,9 +186,13 @@ executables: []
144
186
  extensions: []
145
187
  extra_rdoc_files: []
146
188
  files:
189
+ - ".DS_Store"
147
190
  - ".coveralls.yml"
191
+ - ".fasterer.yml"
148
192
  - ".gitignore"
193
+ - ".reek"
149
194
  - ".rspec"
195
+ - ".rubocop.yml"
150
196
  - ".travis.yml"
151
197
  - Gemfile
152
198
  - LICENSE.txt
@@ -159,9 +205,9 @@ files:
159
205
  - lib/active_report.rb
160
206
  - lib/active_report/array.rb
161
207
  - lib/active_report/base.rb
162
- - lib/active_report/configuration.rb
163
208
  - lib/active_report/hash.rb
164
209
  - lib/active_report/record.rb
210
+ - lib/active_report/settings.rb
165
211
  - lib/active_report/version.rb
166
212
  - lib/generators/active_report/install_generator.rb
167
213
  - lib/generators/active_report/templates/install.rb
@@ -1,10 +0,0 @@
1
- class ActiveReport::Configuration
2
-
3
- attr_accessor :force_encoding, :options
4
-
5
- def initialize
6
- @force_encoding = true
7
- @options = { encoding: "UTF-8" }
8
- end
9
-
10
- end