presenter_rails 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
+ SHA1:
3
+ metadata.gz: b6e00843174079f2bc4d60bb07ea2ecc553a6087
4
+ data.tar.gz: 39f1c037955517799a8d12f5bc57476edceb744e
5
+ SHA512:
6
+ metadata.gz: 59378922fa39c27917f60bb737165527651cd43302b4f68abe2f8bbf4870677ff4087318c764b353b09865e3f543ee3f13cd4e5aef4de39eca5f4beab843e809
7
+ data.tar.gz: 377ce22e472bef7a617c9a9e4bc8a0b0645543f8f32d01af13e65bbbeea63491a6838fc2b8a8eb2064415861923556cb810fb6194c2680834803b9d5854af282
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Singular Resource
2
+ =====================
3
+
4
+ Extracted from decent exposure, attempts to leave the useful parts, and just use `helper_method` to expose your view models.
5
+
6
+ ## DOES
7
+ Allow you to find or initialize a simple resource, removing the boilerplate from CRUD actions.
8
+
9
+
10
+ ## DOES NOT
11
+ Expose the model in any way, scope the query to a collection method if defined, or deal with collections.
12
+
13
+
14
+ ## Use
15
+ It provides a private method that performs a query for the document when invoked, unless the id is not defined (`new`, `create`), in which case it returns an initialized model.
16
+ ```ruby
17
+ singular_resource :patient
18
+ ```
19
+
20
+ #### Strategies
21
+ Like `decent_exposure`, it's configurable, and provides different strategies.
22
+ By default, it uses `StrongParametersStrategy`, which only assigns the attributes if a method name is provided via the `attributes` option.
23
+
24
+ #### Options
25
+ ``` ruby
26
+ :optional => "True if shouldn't fail if document does not exist",
27
+
28
+ :model => "Class or name of the model class",
29
+
30
+ :finder_parameter => "Name of the parameter that has the document's id",
31
+
32
+ :attributes => "Name of the attributes method name if using strong parameters",
33
+
34
+ :param_key => "Name of the parameter that has the document's attributes"
35
+ ```
36
+
37
+ ### Special Thanks
38
+ Singular Resource is a subset of [decent_exposure](https://github.com/voxdolo/decent_exposure).
@@ -0,0 +1,51 @@
1
+ module PresenterRails
2
+ module Presenter
3
+ extend ActiveSupport::Concern
4
+ include SimpleMemoizer
5
+
6
+ module ClassMethods
7
+ def present(*methods)
8
+ methods.flatten!
9
+ presenter_methods = *Presenter.presenter_method_names(methods)
10
+ enforce_private_methods!(presenter_methods)
11
+
12
+ presenter_method *methods
13
+ memoize presenter_methods
14
+ end
15
+
16
+ def presenter_method(*method_names)
17
+ presenters_module = Module.new do
18
+ method_names.each do |name|
19
+ module_eval <<-ruby_eval, __FILE__, __LINE__ + 1
20
+ def #{name}
21
+ controller.send('#{Presenter.presenter_method_name(name)}')
22
+ end
23
+ ruby_eval
24
+ end
25
+ end
26
+ helper presenters_module
27
+ end
28
+
29
+ private
30
+
31
+ def enforce_private_methods!(methods)
32
+ method_set = methods.to_set
33
+ if self.instance_methods.any? {|method| method_set.include?(method) }
34
+ methods = method_set.select {|method| self.instance_method?(method) }
35
+ Kernel.abort "[ERROR] You are exposing presenters by the `#{methods.join(', ')}` method, " \
36
+ "which is either a non private method or overrides an existing method of the same name. " \
37
+ "Consider using a different presenter name\n" \
38
+ "#{caller.first}"
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.presenter_method_names(method_names)
44
+ method_names.map {|name| presenter_method_name(name) }
45
+ end
46
+
47
+ def self.presenter_method_name(name)
48
+ "#{name}_presenter"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ require 'presenter_rails/presenter'
2
+
3
+ ActiveSupport.on_load(:action_controller) do
4
+ include PresenterRails::Presenter
5
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presenter_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simple_memoizer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Presenter helps you expose view models to your views with a declarative
42
+ approach.
43
+ email:
44
+ - maximomussini@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - README.md
49
+ files:
50
+ - README.md
51
+ - lib/presenter_rails.rb
52
+ - lib/presenter_rails/presenter.rb
53
+ homepage: https://github.com/ElMassimo/presenter_rails
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: ViewModels had a baby with helper_method
78
+ test_files: []