render_json_rails 0.2.1 → 0.2.2
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 +4 -4
- data/.gitignore +1 -0
- data/lib/render_json_rails/concern.rb +15 -9
- data/lib/render_json_rails/helper.rb +2 -1
- data/lib/render_json_rails/version.rb +1 -1
- metadata +1 -2
- data/render_json_rails-0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80785e8f96237cbf90167c64bcd74a997d572c4aa94cea4bdd53f21e0ad402c
|
4
|
+
data.tar.gz: e34fb4f9f8af8dc1ef1eb642949721f36256e60a4e646f3cdbdfffa5a042102b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f40743ed807224c5f6b2aa2efe5ea064e91fbdef182889d308a5712d7d9764f8cc3d822198c2712a00f17accf7fecf02da90308ab7026473b1c2775560404438
|
7
|
+
data.tar.gz: 38c1db738769a548b9967572760f846372906b588bdbed3f76bb87671e64038752b3f0337c0aafaa86c6825439a323cd5a1e744644c7778036e08f867f3a8d83
|
data/.gitignore
CHANGED
@@ -49,28 +49,34 @@ module RenderJsonRails
|
|
49
49
|
@render_json_config = config
|
50
50
|
end
|
51
51
|
|
52
|
-
def render_json_options(includes: nil, fields: nil, additional_config: nil)
|
52
|
+
def render_json_options(includes: nil, fields: nil, override_render_json_config: nil, additional_config: nil)
|
53
53
|
raise "należy skonfigurowac render_json metodą: render_json_config" if !defined?(@render_json_config)
|
54
54
|
|
55
|
-
|
55
|
+
if override_render_json_config
|
56
|
+
current_json_config = @render_json_config.merge(override_render_json_config)
|
57
|
+
else
|
58
|
+
current_json_config = @render_json_config
|
59
|
+
end
|
60
|
+
|
61
|
+
name = current_json_config[:name].to_s
|
56
62
|
|
57
|
-
if (fields.blank? || fields[name].blank?) &&
|
63
|
+
if (fields.blank? || fields[name].blank?) && current_json_config[:default_fields].present?
|
58
64
|
fields ||= {}
|
59
|
-
fields[name] =
|
65
|
+
fields[name] = current_json_config[:default_fields].join(',')
|
60
66
|
end
|
61
67
|
|
62
68
|
options = default_json_options(
|
63
69
|
name: name,
|
64
70
|
fields: fields,
|
65
|
-
only:
|
66
|
-
except:
|
67
|
-
methods:
|
68
|
-
allowed_methods:
|
71
|
+
only: current_json_config[:only],
|
72
|
+
except: current_json_config[:except],
|
73
|
+
methods: current_json_config[:methods],
|
74
|
+
allowed_methods: current_json_config[:allowed_methods]
|
69
75
|
)
|
70
76
|
|
71
77
|
if includes
|
72
78
|
include_options = []
|
73
|
-
|
79
|
+
current_json_config[:includes]&.each do |model_name, klass|
|
74
80
|
if includes.include?(model_name.to_s)
|
75
81
|
includes2 = RenderJsonRails::Concern.includes_for_model(includes: includes, model: model_name.to_s)
|
76
82
|
include_options << { model_name => klass.render_json_options(includes: includes2, fields: fields) }
|
@@ -17,7 +17,7 @@ module RenderJsonRails
|
|
17
17
|
# fields[invoice]=number,sales_code
|
18
18
|
# fields[invoice_position]=price_gross
|
19
19
|
# include=positions
|
20
|
-
def render_json(object, additional_config: nil, status: nil, location: nil)
|
20
|
+
def render_json(object, override_render_json_config: nil, additional_config: nil, status: nil, location: nil)
|
21
21
|
raise "objekt nie moze byc null" if object == nil
|
22
22
|
|
23
23
|
if object.class.to_s.include?('ActiveRecord_Relation')
|
@@ -31,6 +31,7 @@ module RenderJsonRails
|
|
31
31
|
options = class_object.render_json_options(
|
32
32
|
includes: includes,
|
33
33
|
fields: params[:fields],
|
34
|
+
override_render_json_config: override_render_json_config,
|
34
35
|
additional_config: additional_config
|
35
36
|
)
|
36
37
|
if params[:formatted] && !Rails.env.development? || params[:formatted] != 'no' && Rails.env.development?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_json_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin
|
@@ -57,7 +57,6 @@ files:
|
|
57
57
|
- lib/render_json_rails/concern.rb
|
58
58
|
- lib/render_json_rails/helper.rb
|
59
59
|
- lib/render_json_rails/version.rb
|
60
|
-
- render_json_rails-0.2.gem
|
61
60
|
- render_json_rails.gemspec
|
62
61
|
homepage: https://github.com/intum/render_json_rails
|
63
62
|
licenses:
|
data/render_json_rails-0.2.gem
DELETED
Binary file
|