hotwire 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hotwire.gemspec +1 -1
- data/lib/hotwire/response/active_record_mixin.rb +1 -1
- data/lib/hotwire/response/base.rb +4 -4
- data/test/response/test_base.rb +6 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/hotwire.gemspec
CHANGED
@@ -14,7 +14,7 @@ module Hotwire
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def set_data_with_active_record_collection(data)
|
17
|
-
data = rows_from_active_record_collection(data) if data.first.is_a?(ActiveRecord::Base)
|
17
|
+
data = rows_from_active_record_collection(data) if data.respond_to?(:first) and data.first.is_a?(ActiveRecord::Base)
|
18
18
|
set_data_without_active_record_collection(data)
|
19
19
|
end
|
20
20
|
|
@@ -40,7 +40,7 @@ module Hotwire
|
|
40
40
|
#
|
41
41
|
# or a sample row of data, represented as a hash keyed as column_name => value:
|
42
42
|
# add_columns({:column_a => 'a1', :column_b => 'b1})
|
43
|
-
# column_name keys are expected to be
|
43
|
+
# column_name keys are expected to be strings.
|
44
44
|
def add_columns(columns)
|
45
45
|
if columns.first.is_a?(Hash)
|
46
46
|
add_columns_from_data_hash(columns)
|
@@ -61,7 +61,7 @@ module Hotwire
|
|
61
61
|
# If passing an array of column_name => value hashes and no columns have been added,
|
62
62
|
# a column will automatically be added for each entry in the first row of data.
|
63
63
|
# If columns have already been added then the data will be filtered to those
|
64
|
-
# columns. column_name keys are expected to be
|
64
|
+
# columns. column_name keys are expected to be strings.
|
65
65
|
#
|
66
66
|
# If passing a hash with :columns key and a :rows key,
|
67
67
|
# :columns should be an array of column ids: ['col_a', 'col_b'...'col_N']
|
@@ -87,7 +87,7 @@ module Hotwire
|
|
87
87
|
# Adds columns to the response based on a sample row of data in the form of a hash
|
88
88
|
# keyed as column_name => value
|
89
89
|
def add_columns_from_data_hash(data)
|
90
|
-
data.first.each do |key, value|
|
90
|
+
data.first.sort.each do |key, value|
|
91
91
|
add_column(column_type_for_value(value), :id => key.to_s, :label => key.to_s)
|
92
92
|
end
|
93
93
|
end
|
@@ -133,7 +133,7 @@ module Hotwire
|
|
133
133
|
# Data is filtered on the columns that exist.
|
134
134
|
def set_data_from_array_of_hashes(data)
|
135
135
|
add_columns(data) if columns.empty?
|
136
|
-
set_data(data.map { |row| self.columns.map { |c| row[c[:id].
|
136
|
+
set_data(data.map { |row| self.columns.map { |c| row[c[:id].to_s] } })
|
137
137
|
end
|
138
138
|
|
139
139
|
# Sets the response data from a two dimensional array of innumerables.
|
data/test/response/test_base.rb
CHANGED
@@ -43,24 +43,24 @@ class TestResponseBase < Test::Unit::TestCase
|
|
43
43
|
context "when columns are not set" do
|
44
44
|
setup do
|
45
45
|
@datetime = Time.utc(2010, 11, 2, 9, 35, 00)
|
46
|
-
@data = [{
|
46
|
+
@data = [{'string_col' => 'a1', 'int_col' => 2, 'decimal_col' => 3.3, 'datetime_col' => @datetime}]
|
47
47
|
@response.set_data(@data)
|
48
48
|
end
|
49
49
|
should "add columns to the response" do
|
50
|
-
expected = [{:id => '
|
51
|
-
{:id => 'int_col', :label => "int_col", :type => 'number'},
|
50
|
+
expected = [{:id => 'datetime_col', :label => "datetime_col", :type => 'datetime'},
|
52
51
|
{:id => 'decimal_col', :label => "decimal_col", :type => 'number'},
|
53
|
-
{:id => '
|
52
|
+
{:id => 'int_col', :label => "int_col", :type => 'number'},
|
53
|
+
{:id => 'string_col', :label => "string_col", :type => 'string'}]
|
54
54
|
assert_equal expected, @response.columns
|
55
55
|
end
|
56
56
|
should "set the data for the response" do
|
57
|
-
assert_equal [[
|
57
|
+
assert_equal [[@datetime, 3.3, 2, 'a1']], @response.data
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context "when columns are already set" do
|
62
62
|
setup do
|
63
|
-
@data = [{
|
63
|
+
@data = [{'col_a' => 'a1', 'col_b' => 'b1', 'col_c' => 'c1'}]
|
64
64
|
@response.add_columns([['string', {:id => 'col_c', :label => 'col_c'}],
|
65
65
|
['string', {:id => 'col_a', :label => 'col_a'}]])
|
66
66
|
@response.set_data(@data)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotwire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Les Freeman
|