jbuilder_optionals 0.0.0
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 +7 -0
- data/lib/jbuilder_optionals.rb +37 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d620173f9b3858b0c5d4fa1a22cbe0d9e7146da8
|
4
|
+
data.tar.gz: b151cad9490514c0f6ea4eee3d1234c5ee3619cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4192780918a422e22fdd130e7507f833869ce22a5dbfee288bbf1a79ee0b0f1a4b21bc594362ac38c23d7849e2c4f71d2ce25e3caaeef7ce9af9daad69b2026d
|
7
|
+
data.tar.gz: a8500c3acc9ddf7a85b89aeda7c087f28c68e5757510dd03c7fdde68d9449d9ecbc1f604298b8476f545c388111fd5fede50191c107e21bd3f6a254fb7bb7768
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'jbuilder/jbuilder_template'
|
2
|
+
module JbuilderOptionals
|
3
|
+
def optional!(key, val)
|
4
|
+
set!(key, val) if @contains&.any?{|i| i == key}
|
5
|
+
end
|
6
|
+
|
7
|
+
def optional_partial!(*args)
|
8
|
+
partial_contains = ::Hash === @contains.last ? @contains.last[args.last[:key]] : nil
|
9
|
+
return unless @contains&.any?{|i| i == args.last[:key]} || @contains.last&.keys&.any?{|i| i == args.last[:key]}
|
10
|
+
if ::Hash === args.last
|
11
|
+
args.last[:contains] = partial_contains
|
12
|
+
else
|
13
|
+
args.push(contains: partial_contains)
|
14
|
+
end
|
15
|
+
if args.last[:key].to_s == args.last[:key].to_s.singularize
|
16
|
+
set!args.last[:key] do
|
17
|
+
partial!(*args)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
set!args.last[:key] do
|
21
|
+
array!args.last[args.last[:key]] do |record|
|
22
|
+
args.last[args.last[:key].to_s.singularize.to_sym] = record
|
23
|
+
partial!(*args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def partial!(*args)
|
30
|
+
@contains = args.last&.fetch(:contains, nil)
|
31
|
+
super(*args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class JbuilderTemplate < Jbuilder
|
36
|
+
prepend ::JbuilderOptionals
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jbuilder_optionals
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Moe Zarrinfam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: you can define your optional fields on a jbuilder template to render
|
14
|
+
it with what fields you want
|
15
|
+
email: moeenzarrinfam@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/jbuilder_optionals.rb
|
21
|
+
homepage: http://rubygems.org/gems/jbuilder-optionals
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.6.14
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: support optional fields for jbuilder templates
|
45
|
+
test_files: []
|