decent_exposure-draper 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ require 'active_support/core_ext'
2
+ require 'decent_exposure'
3
+ require 'draper'
4
+
5
+ require 'decent_exposure-draper/railtie'
6
+ require 'decent_exposure-draper/version'
7
+
8
+ module DecentExposure
9
+ module Draper
10
+ extend ActiveSupport::Concern
11
+
12
+ module ClassMethods
13
+ def expose(name, decorator = nil, &block)
14
+ if block_given?
15
+ super(name, &block)
16
+ else
17
+ super(name, &default_exposure)
18
+ end
19
+
20
+ super_method = instance_method(name)
21
+
22
+ define_method(name) do
23
+ model_or_collection = super_method.bind(self).call
24
+
25
+ if model_or_collection.nil? or model_or_collection.is_a?(::Draper::Base)
26
+ model_or_collection
27
+ else
28
+ begin
29
+ unless decorator.present?
30
+ klass = model_or_collection.respond_to?(:scoped) ? model_or_collection.first.class : model_or_collection.class
31
+ decorator = "#{klass.to_s.classify}Decorator".constantize
32
+ end
33
+ decorator.decorate(model_or_collection)
34
+ rescue NameError
35
+ model_or_collection
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ module DecentExposure
2
+ module Draper
3
+ if defined?(Rails::Railtie)
4
+ class Railtie < Rails::Railtie
5
+ initializer('decent_exposure_draper.extend_action_controller_base', after: 'decent_exposure.extend_action_controller_base') do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ DecentExposure::Draper::Railtie.insert
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ class Railtie
14
+ def self.insert
15
+ ActionController::Base.send(:include, DecentExposure::Draper)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module DecentExposure
2
+ module Draper
3
+ VERSION = '1.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decent_exposure-draper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mario Uher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: draper
16
+ requirement: &70175703998060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70175703998060
25
+ - !ruby/object:Gem::Dependency
26
+ name: decent_exposure
27
+ requirement: &70175703997640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70175703997640
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70175703997220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70175703997220
47
+ - !ruby/object:Gem::Dependency
48
+ name: purdytest
49
+ requirement: &70175703996800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70175703996800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rails
60
+ requirement: &70175703996380 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70175703996380
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70175703995960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70175703995960
80
+ description: Combines both worlds of decent_exposure and draper into one.
81
+ email: uher.mario@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/decent_exposure-draper/railtie.rb
87
+ - lib/decent_exposure-draper/version.rb
88
+ - lib/decent_exposure-draper.rb
89
+ homepage: https://www.github.com/haihappen/decent_exposure-draper
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.13
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Combines both worlds of decent_exposure and draper into one.
113
+ test_files: []
114
+ has_rdoc: