the_grid 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWI3ODZiNmIxNzlkYzkxYzIxNjY5ZWMxNGFmMWZlZWMyNjQ1NGRiNw==
4
+ MzdhN2E2MTBhNzFlMTIxZjVlNTI0ZWEyMzEzZmRiZjU0OWMxMGUwNQ==
5
5
  data.tar.gz: !binary |-
6
- YmVkOGMwNjRjYmJjYTI0MWM3ZmM5ODZmNTkyOTAxZjFjMjdiMDcwMA==
6
+ NGU5MzBiZGVhNDYxN2ZjZDhjYTA5MWY3NGNlZDlkZWIyODM0MzBkNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDA1ZmJmZjIwYjAzNGQyNTFjOWQwYWRkM2UxZjkzZjYzZDg4YjdiOGZkZDVm
10
- ZjUzZTc2YWIzNzA1MTlmMGM2MTI5NmEzOGU1MjE0ZjFjNTM1NjI5Y2U2OGU5
11
- NDVkZmMxYWUxMWRiNmIzYzQwYTIwNzljMTkyYzg2MmFjNzdjN2Q=
9
+ ZTZjNTBkYTQ2MGZlOTZiYThkOTE4OWY5OTQzMjYwMzA5ZmI3NGVkMzJhZTI3
10
+ MWM5OWFhYzhiM2M4OThlZWY5ZmVkMjdkMjg4MWYwM2E5ZTFmNWIwMTg5MmFm
11
+ MjIyZTEyMTJkYTgyMWExYTU4YjU0Yjc0Zjc1YTJkMmZhZDQ2ZjY=
12
12
  data.tar.gz: !binary |-
13
- OWQzNGE2YzlhOGM4NzkxMWViOGNhMzcxMjg1NWFhZjhhZTc0ZTFmM2M5OWFl
14
- NGQ3MTBiMzk1ZGZlZDllNDQwMThiNWQ3ZTFmZTA2ZWZhNzA1NzIyNjhkYTRh
15
- MjY1OWFlNGM5YTIzNjNlNGRlM2RlOTRlZGIxMWJhODFlYWQ4OGE=
13
+ M2Q0ZDlkODY4Yzg2MjZmM2VhMjJiYWFhMWQwMTA2OWU5MmI2YzAxNjYwMzY4
14
+ NjZkZTRkZTJlZTYxYWNmNzQwZTE0MjA1MzE5OWM0ZGYyY2E4ODc2MmRjNzdi
15
+ OGJlMTY5MTc5YmFmNWJlNzU4ZTAxMTMzYmM4MzFkOGZlN2E4MzI=
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
- gem 'cover_me', '>= 1.2.0', :group => :test
@@ -1,11 +1,11 @@
1
1
  module TheGrid
2
2
  class Builder::Context
3
- attr_reader :columns, :options, :scope, :name
3
+ attr_reader :columns, :scope
4
4
 
5
5
  def initialize(options = {}, &dsl)
6
- @scope = options.delete(:scope)
7
- @options = options
8
- @columns = { :id => {:hidden => true} }
6
+ @scope = options.delete(:scope)
7
+ @columns = build_columns_with(options.delete(:id))
8
+ @options = options.merge(:features => [])
9
9
 
10
10
  self.instance_eval(&dsl)
11
11
  end
@@ -21,9 +21,8 @@ module TheGrid
21
21
  if @scope.respond_to?(method_name)
22
22
  @scope.send(method_name, *args, &block)
23
23
  elsif method_name.to_s.ends_with?("ble_columns")
24
- feature = method_name.to_s.chomp("_columns")
25
- mark_columns_with(feature.to_sym, args)
26
- @options[method_name.to_sym] = args
24
+ @options[:features] << method_name.to_s.chomp("_columns").to_sym
25
+ mark_columns_with(@options[:features].last, args)
27
26
  else
28
27
  @options[method_name] = args.size == 1 ? args.first : args
29
28
  end
@@ -34,6 +33,14 @@ module TheGrid
34
33
  column name, attributes.merge(:as => Builder::Context.new(:scope => scope, &block), :scope_name => scope_name)
35
34
  end
36
35
 
36
+ def options
37
+ @options.except(:features)
38
+ end
39
+
40
+ def params
41
+ self.options.merge self.featured_columns
42
+ end
43
+
37
44
  def visible_columns
38
45
  columns.each_with_object({}) do |column, vc|
39
46
  name, options = column
@@ -48,6 +55,12 @@ module TheGrid
48
55
 
49
56
  protected
50
57
 
58
+ def build_columns_with(id_field)
59
+ columns = {}
60
+ columns[id_field || :id] = {:hidden => true} unless id_field === false
61
+ columns
62
+ end
63
+
51
64
  def find_or_build_column(name)
52
65
  @columns[name.to_sym] ||= {}
53
66
  end
@@ -58,6 +71,12 @@ module TheGrid
58
71
  end
59
72
  end
60
73
 
74
+ def featured_columns
75
+ @options[:features].each_with_object({}) do |feature, types|
76
+ types[:"#{feature}_columns"] = columns.select{ |name, attrs| attrs[feature] }.keys
77
+ end
78
+ end
79
+
61
80
  def assemble_row_for(record)
62
81
  columns.each_with_object({}) do |column, row|
63
82
  name, options = column
@@ -9,7 +9,7 @@ module TheGrid
9
9
  end
10
10
 
11
11
  def assemble_with(params)
12
- options = params.merge context.options
12
+ options = params.merge context.params
13
13
  api.compose!(options)
14
14
  stringify as_json_with(options)
15
15
  rescue ArgumentError => error
@@ -1,3 +1,3 @@
1
1
  module TheGrid
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -7,10 +7,20 @@ describe TheGrid::Builder::Context do
7
7
  let(:options) {{ :per_page => 25, :scope => parent_scope }}
8
8
 
9
9
  context "by default" do
10
- it "has hidden id column" do
10
+ it "creates hidden id column" do
11
11
  build_context.columns[:id].should have_key(:hidden)
12
12
  end
13
13
 
14
+ it "creates hidden column with specified primary key name" do
15
+ options[:id] = :key
16
+ build_context.columns[:key].should have_key(:hidden)
17
+ end
18
+
19
+ it "does not create column for primary key if :id equals false" do
20
+ options[:id] = false
21
+ build_context.columns.should have(0).items
22
+ end
23
+
14
24
  it "stores specified options" do
15
25
  build_context.options[:per_page].should eql options[:per_page]
16
26
  end
@@ -39,13 +49,17 @@ describe TheGrid::Builder::Context do
39
49
  columns[:name].values_at(:test, :value).should eql [true, 5]
40
50
  end
41
51
 
42
- it "marks columns as featurable" do
52
+ it "marks columns as featured" do
43
53
  columns = build_context{ searchable_columns :name, :text }.columns
44
54
  columns.slice(:name, :text).should be_all{ |k, v| v[:searchable] == true }
45
55
  end
46
56
 
47
- it "stores featureable columns in options" do
48
- build_context{ searchable_columns :name, :text }.options[:searchable_columns].should eql [:name, :text]
57
+ it "defines featured columns in params" do
58
+ build_context{ searchable_columns :name, :text }.params[:searchable_columns].should eql [:name, :text]
59
+ end
60
+
61
+ it "does not define featured columns in options" do
62
+ build_context{ searchable_columns :name, :text }.options[:searchable_columns].should be_blank
49
63
  end
50
64
 
51
65
  it "accepts single option's values" do
@@ -92,7 +106,7 @@ describe TheGrid::Builder::Context do
92
106
  let(:fields) {{ :title => "item", :id => 5, :live? => false, :short_details => "details" }}
93
107
  let(:records) {[ double(fields), double(fields.merge :live? => true) ]}
94
108
 
95
- context "records" do
109
+ describe "result" do
96
110
  subject { context.assemble(records) }
97
111
  let(:context) { build_plane_context }
98
112
 
@@ -102,7 +116,7 @@ describe TheGrid::Builder::Context do
102
116
  it { should be_all{ |r| r.keys == context.columns.keys }}
103
117
  end
104
118
 
105
- context "any structure" do
119
+ describe "any structure" do
106
120
  subject{ build_plane_context }
107
121
  after(:each){ subject.assemble(records) }
108
122
 
@@ -119,7 +133,7 @@ describe TheGrid::Builder::Context do
119
133
  end
120
134
  end
121
135
 
122
- context "tree-like structure" do
136
+ describe "tree-like structure" do
123
137
  let(:conditional_option) { :if }
124
138
  let(:fields) {{ :id => 5, :live? => false, :permanent => [], :conditional => [], :conditional_block => [] }}
125
139
  after(:each) { build_tree_like_context(conditional_option).assemble(records) }
@@ -179,4 +193,4 @@ describe TheGrid::Builder::Context do
179
193
  TheGrid::Builder::Context.new(options, &dsl)
180
194
  end
181
195
 
182
- end
196
+ 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.7
4
+ version: 1.0.8
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-08 00:00:00.000000000 Z
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord