revealer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/revealer/railtie.rb +17 -0
- data/lib/revealer/version.rb +3 -0
- data/lib/revealer.rb +57 -0
- metadata +102 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Revealer
|
2
|
+
if defined?(Rails::Railtie)
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer('revealer.extend_action_controller_base') do
|
5
|
+
ActiveSupport.on_load(:action_controller) do
|
6
|
+
Revealer::Railtie.insert
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Railtie
|
13
|
+
def self.insert
|
14
|
+
ActionController::Base.send(:include, Revealer)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/revealer.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
require 'draper'
|
3
|
+
|
4
|
+
require 'revealer/railtie'
|
5
|
+
require 'revealer/version'
|
6
|
+
|
7
|
+
module Revealer
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def reveal(name, options = {}, &block)
|
12
|
+
klass, decorator = options[:class], options[:decorator]
|
13
|
+
|
14
|
+
default_reveal = proc do |name|
|
15
|
+
unless klass
|
16
|
+
collection = name.to_s.pluralize
|
17
|
+
|
18
|
+
if respond_to?(collection) && collection != name.to_s && send(collection).respond_to?(:scoped)
|
19
|
+
klass = send(collection)
|
20
|
+
else
|
21
|
+
klass = name.to_s.classify.constantize
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
reveal = if id = params[:"#{name}_id"] || params[:id]
|
26
|
+
klass.find(id)
|
27
|
+
else
|
28
|
+
klass.new
|
29
|
+
end
|
30
|
+
|
31
|
+
reveal.attributes = params[name] unless request.get?
|
32
|
+
|
33
|
+
reveal = case decorator
|
34
|
+
when Class
|
35
|
+
decorator.new(reveal)
|
36
|
+
when true
|
37
|
+
"#{reveal.class.name}Decorator".constantize.new(reveal)
|
38
|
+
end
|
39
|
+
|
40
|
+
reveal
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method(name) do
|
44
|
+
@_reveals ||= {}
|
45
|
+
|
46
|
+
@_reveals[name] ||= if block_given?
|
47
|
+
instance_eval(&block)
|
48
|
+
else
|
49
|
+
instance_exec(name, &default_reveal)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
hide_action(name)
|
54
|
+
helper_method(name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: revealer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mario Uher
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: draper
|
16
|
+
requirement: &70248559080680 !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: *70248559080680
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: action_controller
|
27
|
+
requirement: &70248559080260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70248559080260
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &70248559079840 !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: *70248559079840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: purdytest
|
49
|
+
requirement: &70248559079420 !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: *70248559079420
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &70248559078960 !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: *70248559078960
|
69
|
+
description: The better decent_exposure.
|
70
|
+
email: uher.mario@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/revealer/railtie.rb
|
76
|
+
- lib/revealer/version.rb
|
77
|
+
- lib/revealer.rb
|
78
|
+
homepage: https://www.github.com/haihappen/revealer
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.10
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: The better decent_exposure.
|
102
|
+
test_files: []
|