the_grid 1.0.8 → 1.0.10

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzdhN2E2MTBhNzFlMTIxZjVlNTI0ZWEyMzEzZmRiZjU0OWMxMGUwNQ==
4
+ MTE1YjBhNmMwMmNiZTk4MjJiYTAzYmM4ZTc3Nzk3ZWM1NmRkOGUxNw==
5
5
  data.tar.gz: !binary |-
6
- NGU5MzBiZGVhNDYxN2ZjZDhjYTA5MWY3NGNlZDlkZWIyODM0MzBkNQ==
6
+ YzZkNGM1ZDMxOTZkZjg5YmMzMmExZDg1N2Q5YTEzYjNkOWJmOTNjYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTZjNTBkYTQ2MGZlOTZiYThkOTE4OWY5OTQzMjYwMzA5ZmI3NGVkMzJhZTI3
10
- MWM5OWFhYzhiM2M4OThlZWY5ZmVkMjdkMjg4MWYwM2E5ZTFmNWIwMTg5MmFm
11
- MjIyZTEyMTJkYTgyMWExYTU4YjU0Yjc0Zjc1YTJkMmZhZDQ2ZjY=
9
+ YWE1NDcwMTYwZDAzOWRiMTAwN2M2ZmIzYzBhOGVlZjYzZjI4ZDcyOTZjOGMy
10
+ NDY1MjgyNGE4ZmU2ZDhkOTk4MTE3NTJhYWIxNzdjZTMyMzE2ZGJhYmIzZTBk
11
+ ODk2OWUxNjFjNTMxMmViYTExMDI3MmE0ZTE2MzU2NWFiM2UzNzg=
12
12
  data.tar.gz: !binary |-
13
- M2Q0ZDlkODY4Yzg2MjZmM2VhMjJiYWFhMWQwMTA2OWU5MmI2YzAxNjYwMzY4
14
- NjZkZTRkZTJlZTYxYWNmNzQwZTE0MjA1MzE5OWM0ZGYyY2E4ODc2MmRjNzdi
15
- OGJlMTY5MTc5YmFmNWJlNzU4ZTAxMTMzYmM4MzFkOGZlN2E4MzI=
13
+ NDEyMWRjYjUxNmM5MzUwYzA1YWJmZDM1NDBkMzIzZDY4MzllOTlkZDJkZGM3
14
+ NTc1MDU5MzI4YjdhMzM3ZjljYWRmZTMxZjVlMmQ1NGM1NDQ3NjM4MjBkYTQ0
15
+ MWY5YzBlMTY1NjM0N2ZjNmY5NTU5YmY4NTg0YjlmNzhkNDYwMzg=
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use --create 1.9.3-p392@grid
1
+ rvm use 1.9.3-p392@grid --create
data/README.md CHANGED
@@ -239,6 +239,7 @@ Sometimes it's reasonable to add extra meta information into response:
239
239
  ```ruby
240
240
  grid_for @articles, :per_page => 2 do
241
241
  searchable_columns :title, :created_at
242
+ editable_columns :title
242
243
 
243
244
  # specify any kind of meta parameter
244
245
  server_time Time.now
@@ -256,15 +257,17 @@ The previous example is converted into:
256
257
  "server_time": "2013-03-17 02:11:05 +0200",
257
258
  "my_option": "Something important for Frontend side"
258
259
  },
259
- "columns": {
260
- "title": {
260
+ "columns": [
261
+ {
262
+ "name": "title",
261
263
  "searchable": true,
262
264
  "editable": true
263
265
  },
264
- "created_at": {
266
+ {
267
+ "name": "created_at",
265
268
  "searchable": true
266
269
  }
267
- },
270
+ ],
268
271
  "max_page": 3,
269
272
  "items": [
270
273
  {
@@ -42,10 +42,9 @@ module TheGrid
42
42
  end
43
43
 
44
44
  def visible_columns
45
- columns.each_with_object({}) do |column, vc|
46
- name, options = column
45
+ columns.each_with_object({}) do |(name,options), vc|
47
46
  vc[name] = options.except(:as, :if, :unless) unless options[:hidden]
48
- vc[name] = options[:as].visible_columns if options[:as].respond_to?(:visible_columns)
47
+ vc[name] = {:columns => options[:as].visible_columns} if options[:as].respond_to?(:visible_columns)
49
48
  end
50
49
  end
51
50
 
@@ -23,15 +23,24 @@ module TheGrid
23
23
  end
24
24
 
25
25
  def as_json_with(options)
26
- {}.tap do |json|
27
- json[:meta], json[:columns] = context.options.except(:delegate, :search_over), context.visible_columns if options[:with_meta]
28
- json[:max_page] = api.options[:max_page]
29
- json[:items] = context.assemble(api.relation)
26
+ json = {:max_page => api.options[:max_page], :items => context.assemble(api.relation)}
27
+ if options[:with_meta]
28
+ json[:meta] = context.options.except(:delegate, :search_over)
29
+ json[:columns] = columns_as_array(context.visible_columns)
30
30
  end
31
+ json
31
32
  end
32
33
 
33
34
  def as_json_message(status, message)
34
35
  {:status => status, :message => message}
35
36
  end
37
+
38
+ def columns_as_array(columns)
39
+ columns.map do |name, options|
40
+ options[:columns] = columns_as_array(options[:columns]) if options[:columns].is_a? Hash
41
+ options.merge :name => name
42
+ end
43
+ end
44
+
36
45
  end
37
46
  end
@@ -1,3 +1,3 @@
1
1
  module TheGrid
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.10"
3
3
  end
@@ -93,12 +93,16 @@ describe TheGrid::Builder::Context do
93
93
  context "when collects visible columns" do
94
94
  let(:parent_scope){ double(:dsl => Proc.new{ column :title; column :name, :hidden => true }) }
95
95
 
96
+ it "returns hash" do
97
+ build_context(&parent_scope.dsl).visible_columns.should be_kind_of Hash
98
+ end
99
+
96
100
  it "returns only visible columns" do
97
101
  build_context(&parent_scope.dsl).visible_columns.keys.should eql [:title]
98
102
  end
99
103
 
100
104
  it "respects visible columns of nested scopes" do
101
- build_context{ scope_for(:children, &dsl) }.visible_columns[:children].keys.should eql [:title]
105
+ build_context{ scope_for(:children, &dsl) }.visible_columns[:children][:columns].keys.should eql [:title]
102
106
  end
103
107
  end
104
108
 
@@ -9,7 +9,8 @@ describe TheGrid::Builder::Json do
9
9
  let(:context) { create_context.tap { |c| c.stub(:assemble => [1,2,3,4]) } }
10
10
  let(:params) {{ :cmd => [:sort], :field => :name, :order => :desc }}
11
11
 
12
- let(:meta) {{ "meta" => {"api_key" => context.options[:api_key]}, "columns" => context.visible_columns.stringify_keys }}
12
+ let(:meta) {{ "meta" => {"api_key" => context.options[:api_key]}, "columns" => columns }}
13
+ let(:columns) { context.visible_columns.stringify_keys.map{ |n, o| o.merge "name" => n } }
13
14
  let(:json_schema) {{ "max_page" => 25, "items" => context.assemble }}
14
15
  let(:assembled_result) { JSON.parse(subject.assemble_with(params)) }
15
16
 
data/the_grid.gemspec CHANGED
@@ -18,7 +18,10 @@ Provides json API for building ActiveRecord::Relation's. It makes much easier t
18
18
  Tags: json, grid, api, grid builder, activerecord relation builder, relation
19
19
  EOF
20
20
 
21
- s.rubyforge_project = "the_grid"
21
+ s.post_install_message = <<-_MSG_
22
+ Columns' definition in json response is changed
23
+ because javascript does not remember the order of properties in object.
24
+ _MSG_
22
25
 
23
26
  s.files = `git ls-files`.split("\n")
24
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -27,8 +30,7 @@ EOF
27
30
 
28
31
  s.add_dependency 'activerecord', '>= 3.0'
29
32
  s.add_dependency 'json'
30
-
31
- # specify any dependencies here; for example:
33
+
32
34
  s.add_development_dependency "bundler", ">= 1.0.0"
33
35
  s.add_development_dependency "rspec", "~> 2.13"
34
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergiy Stotskiy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
12
+ date: 2013-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -117,7 +117,8 @@ homepage: http://github.com/stalniy/grid
117
117
  licenses:
118
118
  - MIT
119
119
  metadata: {}
120
- post_install_message:
120
+ post_install_message: ! " Columns' definition in json response is changed\n because
121
+ javascript does not remember the order of properties in object.\n"
121
122
  rdoc_options: []
122
123
  require_paths:
123
124
  - lib
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  requirements: []
135
- rubyforge_project: the_grid
136
+ rubyforge_project:
136
137
  rubygems_version: 2.0.3
137
138
  signing_key:
138
139
  specification_version: 4