action_controller-expose 0.1.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/.gitignore +4 -0
- data/Gemfile +3 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/action_controller-expose.gemspec +28 -0
- data/lib/action_controller/expose/version.rb +7 -0
- data/lib/action_controller/expose.rb +41 -0
- metadata +108 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 60d6bf48c45baf490f5c837f63fb7cb349da5f692b5bfabb2d00f74853d5f705
|
|
4
|
+
data.tar.gz: 56f19e086d56afa78f8f7875f370eb3644aaf0c75ab00d24840138cd865b265e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 206e820d6a4c09761684f84f29776ac9db05dcf15d8449c63943f152cf72565c96542cbc5c5392cac91cc984b7c4177a98e2a8eaf704b58bf453f1efef11bc9e
|
|
7
|
+
data.tar.gz: 5021ab0bbd41e2cb3dbb9d8857d499391e6df59f19e6ba1f17cde6d6aec414ab2e806c08f2299a61b92c22d6419b7d274d2f343632d3345658abd965ca5735b0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# action_controller-expose
|
|
2
|
+
|
|
3
|
+
Declarative helper-accessible readers (with optional lazy memoization) for `ActionController`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
class CommentsController < ApplicationController
|
|
9
|
+
# Multiple attr_reader + helper_method declarations.
|
|
10
|
+
# Controller actions assign @foo / @bar; views read `foo` / `bar`.
|
|
11
|
+
expose :foo, :bar
|
|
12
|
+
|
|
13
|
+
# Lazy memoized reader. First call runs the block, later calls return cached
|
|
14
|
+
# result. Memoization via `instance_variable_defined?`, so nil/false cache.
|
|
15
|
+
expose :comment, -> { Comment.find(params[:id]) }
|
|
16
|
+
expose :audition, -> { Audition.medium_ids_including(comment.medium_id).first }
|
|
17
|
+
expose :shoot, -> { audition.shoots.first }
|
|
18
|
+
|
|
19
|
+
# Or with a block:
|
|
20
|
+
expose(:current_thing) { Thing.find(params[:thing_id]) }
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
All forms call `helper_method`, so the views can call the names without `@`.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem "action_controller-expose"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative "lib/action_controller/expose/version"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "action_controller-expose"
|
|
5
|
+
spec.version = ActionController::Expose::VERSION
|
|
6
|
+
spec.authors = ["Micah Geisel"]
|
|
7
|
+
spec.email = ["micah@botandrose.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = %q{Declarative helper-accessible readers (with optional lazy memoization) for ActionController.}
|
|
10
|
+
spec.description = %q{`expose :foo` defines an attr_reader and helper_method. `expose :foo, -> { ... }` (or with a block) defines a memoized reader. Replaces the boilerplate of attr_reader + helper_method + def.}
|
|
11
|
+
spec.homepage = "https://github.com/botandrose/action_controller-expose"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
|
14
|
+
|
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
17
|
+
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_runtime_dependency "actionpack"
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler"
|
|
26
|
+
spec.add_development_dependency "rake"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "action_controller/expose/version"
|
|
4
|
+
require "action_controller"
|
|
5
|
+
|
|
6
|
+
module ActionController
|
|
7
|
+
module Expose
|
|
8
|
+
# Declares helper-accessible reader methods on the controller.
|
|
9
|
+
#
|
|
10
|
+
# expose :foo, :bar # attr_reader + helper_method (controller assigns @foo / @bar)
|
|
11
|
+
# expose :foo, -> { ... } # memoized: first call runs the lambda, later calls return the cached result
|
|
12
|
+
# expose(:foo) { ... } # same, with a block
|
|
13
|
+
#
|
|
14
|
+
# The memoizing form uses instance_variable_defined? so nil/false cache.
|
|
15
|
+
def expose(*names, &block)
|
|
16
|
+
if block
|
|
17
|
+
define_exposed(names.first, &block)
|
|
18
|
+
elsif names.length == 2 && names.last.respond_to?(:call)
|
|
19
|
+
define_exposed(names.first, &names.last)
|
|
20
|
+
else
|
|
21
|
+
names.each do |name|
|
|
22
|
+
attr_reader name
|
|
23
|
+
helper_method name
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def define_exposed(name, &block)
|
|
31
|
+
ivar = "@#{name}"
|
|
32
|
+
define_method(name) do
|
|
33
|
+
return instance_variable_get(ivar) if instance_variable_defined?(ivar)
|
|
34
|
+
instance_variable_set(ivar, instance_exec(&block))
|
|
35
|
+
end
|
|
36
|
+
helper_method name
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
ActionController::Base.extend ActionController::Expose
|
metadata
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: action_controller-expose
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Micah Geisel
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-05-11 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: actionpack
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: bundler
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rspec
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.0'
|
|
68
|
+
description: "`expose :foo` defines an attr_reader and helper_method. `expose :foo,
|
|
69
|
+
-> { ... }` (or with a block) defines a memoized reader. Replaces the boilerplate
|
|
70
|
+
of attr_reader + helper_method + def."
|
|
71
|
+
email:
|
|
72
|
+
- micah@botandrose.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".gitignore"
|
|
78
|
+
- Gemfile
|
|
79
|
+
- README.md
|
|
80
|
+
- Rakefile
|
|
81
|
+
- action_controller-expose.gemspec
|
|
82
|
+
- lib/action_controller/expose.rb
|
|
83
|
+
- lib/action_controller/expose/version.rb
|
|
84
|
+
homepage: https://github.com/botandrose/action_controller-expose
|
|
85
|
+
licenses:
|
|
86
|
+
- MIT
|
|
87
|
+
metadata:
|
|
88
|
+
homepage_uri: https://github.com/botandrose/action_controller-expose
|
|
89
|
+
source_code_uri: https://github.com/botandrose/action_controller-expose
|
|
90
|
+
rdoc_options: []
|
|
91
|
+
require_paths:
|
|
92
|
+
- lib
|
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: 3.0.0
|
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
requirements: []
|
|
104
|
+
rubygems_version: 3.6.2
|
|
105
|
+
specification_version: 4
|
|
106
|
+
summary: Declarative helper-accessible readers (with optional lazy memoization) for
|
|
107
|
+
ActionController.
|
|
108
|
+
test_files: []
|