cloudxls 0.5.1 → 0.6.0

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.
@@ -92,9 +92,17 @@ class Range
92
92
  end
93
93
 
94
94
  class Hash
95
- def as_csv(options = nil)
96
- map do |key, val|
97
- val.as_csv(options)
95
+ def as_csv(options = {})
96
+ attribute_names = keys
97
+
98
+ if (only = options[:only])
99
+ attribute_names = Array(only)
100
+ elsif (except = options[:except])
101
+ attribute_names -= Array(except)
102
+ end
103
+
104
+ attribute_names.map do |key|
105
+ self[key].as_csv
98
106
  end
99
107
  end
100
108
  end
@@ -90,9 +90,9 @@ module CloudXLS
90
90
 
91
91
 
92
92
  def self.scope_enumerator(scope)
93
- if (scope.respond_to?(:arel) &&
94
- scope.arel.orders.blank? &&
95
- scope.arel.taken.blank?)
93
+ if scope.respond_to?(:arel) &&
94
+ scope.arel.orders.blank? &&
95
+ scope.arel.taken.blank?
96
96
  :find_each
97
97
  else
98
98
  :each
@@ -111,9 +111,7 @@ module CloudXLS
111
111
  # CloudXLS::Util.titles_for_serialize_options(Post.new, only: [:author, :title], method: [:slug])
112
112
  # # => ['title', 'author', 'slug']
113
113
  #
114
- def self.titles_for_serialize_options(record, options = nil)
115
- options ||= {}
116
-
114
+ def self.titles_for_serialize_options(record, options = {})
117
115
  attribute_names = record.attributes.keys
118
116
  if only = options[:only]
119
117
  arr = []
@@ -1,3 +1,3 @@
1
1
  module CloudXLS
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/cloudxls.rb CHANGED
@@ -12,7 +12,7 @@ require 'cloudxls/csv_writer'
12
12
 
13
13
  module CloudXLS
14
14
  @https = true
15
- @api_base = 'cloudxls.com'.freeze
15
+ @api_base = 'api.cloudxls.com'.freeze
16
16
  @api_key = ENV["CLOUDXLS_API_KEY"]
17
17
  # @ssl_bundle_path = File.dirname(__FILE__) + '/data/ca-certificates.crt'
18
18
  @verify_ssl_certs = true
@@ -23,7 +23,7 @@ module CloudXLS
23
23
 
24
24
  def self.api_url(path = '')
25
25
  # @api_base + url
26
- "http#{@https ? 's' : ''}://#{@api_key}:@#{@api_base}/api/v1/#{path}"
26
+ "http#{@https ? 's' : ''}://#{@api_key}:@#{@api_base}/v1/#{path}"
27
27
  end
28
28
 
29
29
  class XpipeResponse
@@ -5,6 +5,16 @@ describe "as_csv" do
5
5
  expect( {:foo => 1, :bar => Date.new(2013,12,24)}.as_csv ).to eq([1,'2013-12-24'])
6
6
  end
7
7
 
8
+ it "should handle Hash with :only" do
9
+ hash = {:foo => "foo", :bar => "bar"}
10
+ expect( hash.as_csv(:only => :foo) ).to eq(["foo"])
11
+ expect( hash.as_csv(:only => [:foo]) ).to eq(["foo"])
12
+ expect( hash.as_csv(:only => [:bar]) ).to eq(["bar"])
13
+ expect( hash.as_csv(:only => [:foo, :bar]) ).to eq(["foo", "bar"])
14
+ expect( hash.as_csv(:only => [:bar, :foo]) ).to eq(["bar", "foo"])
15
+ #expect( hash.as_csv(:only => [:bar, :baz, :foo]) ).to eq(["foo", nil, "bar"])
16
+ end
17
+
8
18
  it "should handle Array" do
9
19
  expect( [1, Date.new(2013,12,24)].as_csv ).to eq([1,'2013-12-24'])
10
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudxls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client