fern-presenter 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 19b132a2612b61948a6b794177acb236c7328f0a6a620eee622f38b9b13a567f
4
+ data.tar.gz: a3171ae401e39f6d8ae667b4aa479aa7d00a4372b65afb9d5aaff5bab692b078
5
+ SHA512:
6
+ metadata.gz: d80155f6e27bbbc91dad2a7a74566d9d33c1031b41900a74a4154c5e71760d34c5ddf87bb6e62146ad0a4266e4d182af399e9404a9c7f475166c2f68b442a00d
7
+ data.tar.gz: 5d699bd440e281d387e5d57d87e5da62cb064b137aef103bd8cc862d036e413e07f462b7e2a9c54075b1e49e759a109a1fa04c266a36de99a855926a27e71031
@@ -0,0 +1 @@
1
+ require 'fern/presenter'
@@ -0,0 +1,25 @@
1
+ require 'fern/presenter/dsl'
2
+
3
+ module Fern
4
+ module Presenter
5
+ extend ActiveSupport::Concern
6
+
7
+ attr_reader :presenter
8
+
9
+ included do
10
+ def present(object, **opts)
11
+ render json: render_presenter(object, **opts)
12
+ end
13
+
14
+ def render_presenter(object, **opts)
15
+ presenter = fern[action_name.to_sym][:presenter]
16
+
17
+ if object.is_a?(Array) || object.is_a?(ActiveRecord::Relation)
18
+ object.map { |el| presenter.new(el).as_json(**opts) }
19
+ else
20
+ presenter.new(object).as_json(**opts)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'fern/api'
2
+
3
+ module Fern
4
+ module Presenter
5
+ module Dsl
6
+ def self.included(receiver)
7
+ receiver.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ end
12
+
13
+ def presenter(klass)
14
+ @controller.fern[@name][:presenter] = klass
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ Fern::Api::Endpoint.class_eval { include Fern::Presenter::Dsl }
@@ -0,0 +1,5 @@
1
+ module Fern
2
+ module Presenter
3
+ VERSION = '0.0.2'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fern-presenter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Kestell
8
+ - Ryan Andersen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-03-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '12.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '12.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.74.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.74.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: fern-api
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: actionpack
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '5.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '5.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: activesupport
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '5.0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '5.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: fern-api
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: Presenter support for Fern.
113
+ email:
114
+ - kyle@kestell.org
115
+ - itsryanandersen@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - lib/fern-presenter.rb
121
+ - lib/fern/presenter.rb
122
+ - lib/fern/presenter/dsl.rb
123
+ - lib/fern/presenter/version.rb
124
+ homepage: https://github.com/fern-rb/fern-presenter
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.3.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.0.6
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Fern Presenter
147
+ test_files: []