introspective_grape 0.2.0 → 0.2.2

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: d2f679318dbf2d22e2af0c95708eee64adf103fb
4
- data.tar.gz: 786a80ed73eec2168392904e459266dda8b22663
3
+ metadata.gz: 6af99e9a2be82ee669829ac17f9e84b767d74e12
4
+ data.tar.gz: eac78da439dd9c35844cbafd0cfd23428c3500de
5
5
  SHA512:
6
- metadata.gz: 8ebf9eb5fd7859107a9d412cfe09728eb839191167b46cbd6d85ff9b1d740764cddc3acb621488c66e6b2d1a659f29c0b012c92948a35a478509e53012a5a5de
7
- data.tar.gz: 9c8b93a2952bb15a2b8ba751efb1d49d00156a4267988068f91ce81ab71dad6860281b4d21c9d3424e6b162fd75fed26e835dbdf3e4d696d973e08700773ea1e
6
+ metadata.gz: 4531fc66b10fd1f3e84778572f7ba2c0e6d9a6c27f902ae6d13ebe55da68c6ab87ad6f19a6e37883678fc3bddcaeeab4f31cc790509c9ab9041249b36ac0aafd
7
+ data.tar.gz: 82660a9b2cd9683e78b4f2aacb11430e66a9a68a171f0ab3fdb4811613f264d4ebea20d51a9d0b27f3dbd7af5fa363ed3d2f76180755a8abb07246a30759111c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ 0.2.2 10/20/2016
3
+ ==============
4
+
5
+ ### Bug Fix
6
+
7
+ The default pagination values for Kaminari in snake case were overwriting the passed values
8
+ in camel case, update the camel_snake_keys dependency so key conflicts resolve in favor of
9
+ the expected convention.
10
+
11
+ 0.2.1 10/20/2016
12
+ ==============
13
+
14
+ Require explicit declarations for index filters using `filter_on :attribute`. Automatically generate filters on all fields as before using `filter_on :all`.
15
+
16
+ Defer endpoint documentation to <action>_documentation class methods on the API, so docs can be written.
17
+
2
18
  0.2.0 10/12/2016
3
19
  ==============
4
20
 
data/README.md CHANGED
@@ -125,18 +125,27 @@ creating bulk update endpoints for nested models.
125
125
 
126
126
  ## Filtering and Searching
127
127
 
128
- IntrospectiveGrape will automatically generate and parse filters on all exposed fields in the API.
128
+ Simple filters on field values (and start and end values for timestamps) can be added with the `filter_on` declaration. Declaring `filter_on :all` will add filters for every attribute of the model.
129
+
130
+ ```
131
+ class MyModelAPI < IntrospectiveGrape::API
132
+ filter_on :my_attribute, :my_other_attribute
133
+ end
134
+ ```
129
135
 
130
136
  Multiple values can be specified at once for Integer attributes that end in "id" (i.e. conventional primary and foreign keys) at once by passing a comma separated list of IDs.
131
137
 
132
138
  For timestamp attributes it will generate `<name_of_timestamp>_start` and `<name_of_timestamp>_end` constraints.
133
139
 
140
+ There is also a special "filter" filter, that allows a JSON hash to be passed of attributes and values: this allows more complex filtering if one is familiar with ActiveRecord's query conventions.
141
+
134
142
  ### Overriding Filter Queries
135
143
 
136
144
  If, e.g., a field is some sort of complex composite rather than a simple field value you can override the default behavior (`where(field: params[field])`) by adding a query method on the model class:
137
145
 
138
146
  ```
139
147
  class MyAPI < IntrospectiveGrape::API
148
+ filter_on :my_composite_field
140
149
  restful MyModel, [my_composite_field]
141
150
  end
142
151
 
@@ -169,6 +178,9 @@ class MyModel
169
178
  end
170
179
  ```
171
180
 
181
+ ## Documenting Endpoints
182
+
183
+ If you wish to provide additional documentation for end points you can define `<action>_documentation` methods in the API class.
172
184
 
173
185
  ## Pagination
174
186
 
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency 'grape-swagger', '~>0.11.0'
28
28
  s.add_dependency 'grape-kaminari', '~>0.1.9'
29
29
  s.add_dependency 'pundit'
30
- s.add_dependency 'camel_snake_keys', '~>0.0.2'
30
+ s.add_dependency 'camel_snake_keys', '~>0.0.4'
31
31
 
32
32
  if RUBY_PLATFORM == 'java'
33
33
  #s.add_development_dependency "jdbc-sqlite3"
@@ -6,6 +6,7 @@ module IntrospectiveGrape
6
6
  extend IntrospectiveGrape::Helpers
7
7
  extend IntrospectiveGrape::Filters
8
8
  extend IntrospectiveGrape::Traversal
9
+ extend IntrospectiveGrape::Doc
9
10
 
10
11
  # Allow files to be uploaded through ActionController:
11
12
  ActionController::Parameters::PERMITTED_SCALAR_TYPES.push Rack::Multipart::UploadedFile, ActionController::Parameters
@@ -154,7 +155,7 @@ module IntrospectiveGrape
154
155
  simple_filters(klass, model, api_params)
155
156
 
156
157
  dsl.desc "list #{name}" do
157
- detail "returns list of all #{name}"
158
+ detail klass.index_documentation || "returns list of all #{name}"
158
159
  end
159
160
  dsl.params do
160
161
  klass.declare_filter_params(self, klass, model, api_params)
@@ -182,7 +183,7 @@ module IntrospectiveGrape
182
183
  name = routes.last.name.singularize
183
184
  klass = routes.first.klass
184
185
  dsl.desc "retrieve a #{name}" do
185
- detail "returns details on a #{name}"
186
+ detail klass.show_documentation || "returns details on a #{name}"
186
187
  end
187
188
  dsl.get ":#{routes.last.swaggerKey}" do
188
189
  authorize @model, :show?
@@ -195,7 +196,7 @@ module IntrospectiveGrape
195
196
  klass = routes.first.klass
196
197
  root = routes.first
197
198
  dsl.desc "create a #{name}" do
198
- detail "creates a new #{name} record"
199
+ detail klass.create_documentation || "creates a new #{name} record"
199
200
  end
200
201
  dsl.params do
201
202
  klass.generate_params(self, klass, :create, model, api_params)
@@ -216,7 +217,7 @@ module IntrospectiveGrape
216
217
  klass = routes.first.klass
217
218
  name = routes.last.name.singularize
218
219
  dsl.desc "update a #{name}" do
219
- detail "updates the details of a #{name}"
220
+ detail klass.update_documentation || "updates the details of a #{name}"
220
221
  end
221
222
  dsl.params do
222
223
  klass.generate_params(self, klass, :update, model, api_params)
@@ -234,7 +235,7 @@ module IntrospectiveGrape
234
235
  klass = routes.first.klass
235
236
  name = routes.last.name.singularize
236
237
  dsl.desc "destroy a #{name}" do
237
- detail "destroys the details of a #{name}"
238
+ detail klass.destroy_documentation || "destroys the details of a #{name}"
238
239
  end
239
240
  dsl.delete ":#{routes.last.swaggerKey}" do
240
241
  authorize @model, :destroy?
@@ -0,0 +1,9 @@
1
+ module IntrospectiveGrape
2
+ module Doc
3
+ def index_documentation; end
4
+ def show_documentation; end
5
+ def create_documentation; end
6
+ def update_documentation; end
7
+ def destroy_documentation; end
8
+ end
9
+ end
@@ -14,8 +14,20 @@ module IntrospectiveGrape::Filters
14
14
  @custom_filters
15
15
  end
16
16
 
17
+ def filter_on(*args)
18
+ filters( *args )
19
+ end
20
+
21
+ def filters(*args)
22
+ @filters ||= []
23
+ @filters = @filters+args if args.present?
24
+ @filters
25
+ end
26
+
17
27
  def simple_filters(klass, model, api_params)
18
- @simple_filters ||= api_params.select {|p| p.is_a? Symbol }.map { |field|
28
+ @simple_filters ||= api_params.select {|p| p.is_a? Symbol }.select {|field|
29
+ filters.include?(:all) || filters.include?(field)
30
+ }.map { |field|
19
31
  (klass.param_type(model,field) == DateTime ? ["#{field}_start", "#{field}_end"] : field.to_s)
20
32
  }.flatten
21
33
  end
@@ -55,7 +67,7 @@ module IntrospectiveGrape::Filters
55
67
  dsl.optional filter, details
56
68
  end
57
69
 
58
- dsl.optional :filter, type: String, description: "JSON of conditions for query. If you're familiar with ActiveRecord's query conventions you can build more complex filters, e.g. against included child associations, e.g. {\"<association_name>_<parent>\":{\"field\":\"value\"}}"
70
+ dsl.optional :filter, type: String, description: "JSON of conditions for query. If you're familiar with ActiveRecord's query conventions you can build more complex filters, e.g. against included child associations, e.g. {\"&lt;association_name&gt;_&lt;parent&gt;\":{\"field\":\"value\"}}" if filters.include?(:all) || filters.include?(:filter)
59
71
 
60
72
  end
61
73
 
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.2".freeze
3
3
  end
@@ -1,6 +1,7 @@
1
1
  module IntrospectiveGrape
2
2
  autoload :API, 'introspective_grape/api'
3
3
  autoload :CamelSnake, 'introspective_grape/camel_snake'
4
+ autoload :Doc, 'introspective_grape/doc'
4
5
  autoload :Filters, 'introspective_grape/filters'
5
6
  autoload :Helpers, 'introspective_grape/helpers'
6
7
  autoload :Traversal, 'introspective_grape/traversal'
@@ -5,6 +5,8 @@ class Dummy::LocationAPI < IntrospectiveGrape::API
5
5
 
6
6
  default_includes Location, :child_locations, :gps, :beacons, :locatables
7
7
 
8
+ filter_on :name, :filter
9
+
8
10
  restful Location, [:name, :kind,
9
11
  {gps_attributes: [:id, :lat, :lng, :alt, :_destroy]},
10
12
  {beacons_attributes: [:id, :company_id, :mac_address, :uuid, :major, :minor, :_destroy]},
@@ -6,6 +6,8 @@ class Dummy::UserAPI < IntrospectiveGrape::API
6
6
  exclude_actions Role, :show,:update
7
7
  exclude_actions UserProjectJob, :show,:update
8
8
 
9
+ filter_on :all
10
+
9
11
  restful User, [:id, :email, :password, :first_name, :last_name, :skip_confirmation_email,
10
12
  :created_at, :updated_at,
11
13
  user_project_jobs_attributes: [:id, :job_id, :project_id, :_destroy],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: introspective_grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 0.0.2
109
+ version: 0.0.4
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: 0.0.2
116
+ version: 0.0.4
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: sqlite3
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -271,6 +271,7 @@ files:
271
271
  - lib/introspective_grape.rb
272
272
  - lib/introspective_grape/api.rb
273
273
  - lib/introspective_grape/camel_snake.rb
274
+ - lib/introspective_grape/doc.rb
274
275
  - lib/introspective_grape/filters.rb
275
276
  - lib/introspective_grape/formatter/camel_json.rb
276
277
  - lib/introspective_grape/helpers.rb