view_delegates 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 560994ea7de1356f1e32811a09cc2d09d2f7c1680f84b4b0522564f4cb7a4ce1
4
- data.tar.gz: 3e73b82aca43a8f57421bb45e112a085ac75b66cc37608f8861680260f2d8fbf
3
+ metadata.gz: 5ae035f744ed2500538cec3961ed5b0cadc1ae4f47c3b006e165490d2e951ef0
4
+ data.tar.gz: 23a68255593a6609f5d1bba32a1765026806392601271ffe5897a9c92e63fa01
5
5
  SHA512:
6
- metadata.gz: 823cf54f2f78a396422e51c1a08141892fefcd9827b307f4b8538ea7d4efa0c9fdd3886f2a1fd8ba8d0ad42ca98f8d28bcdaa1a9e1a305032836acf88192face
7
- data.tar.gz: a3f418e905c5377ca304863e1c1d80718500e49915253563e80b625ca3b7ea9c9ca257ff67c873b307c745e3eaaba63d077db65849e041a5f6ee4d917c6bc0a4
6
+ metadata.gz: 2f15b7a9992a52d920af7d4e24f990fdda381438d1d89bc5eba3975b8d0d34467e679a2630935cfafdb136eb73234e99663e960fd75484697d23632ce252bb42
7
+ data.tar.gz: 8797505d4f520d790f03c9070db41c306ebe426d5f3a3140de5b725e4e427b878eec0f7558b9b6dd0168fe807a08f4f7a38f8d014d2061d197c226a8802cf766
data/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
  # ViewDelegates
3
3
  ViewDelegates makes easy to write reusable view components with decoupled functionality from
4
4
  the active record models
5
-
5
+ # Requirements
6
+ Only tested with ruby 2.5 and rails 5.1.6, should work with any rails version over 5.0
7
+ but i don't know about the ruby version. Could'nt made travis work
8
+ #Usage
6
9
  Create a ruby class implementing this gem base class
7
10
  ViewDelegates::ViewDelegate. I recommend to place the view delegates
8
11
  under a folder on your applications app named '/view_delegates'. Then
@@ -44,8 +47,6 @@ To know where your class will look for your view, open your console and call .vi
44
47
 
45
48
  ```
46
49
 
47
- ## Usage
48
- How to use my plugin.
49
50
 
50
51
  ## Installation
51
52
  Add this line to your application's Gemfile:
@@ -19,6 +19,9 @@ module ViewDelegates
19
19
  @@ar_models.each do |t|
20
20
  send("#{t}=", view_data[t]) if view_data[t]
21
21
  end
22
+ @@properties.each do |t|
23
+ send("#{t}=", view_data[t]) if view_data[t]
24
+ end
22
25
  end
23
26
 
24
27
  # Renders as a string the view passed as params
@@ -40,6 +43,20 @@ module ViewDelegates
40
43
  locals: locals)
41
44
  end
42
45
  class << self
46
+
47
+ def new *args
48
+ if defined? @@polymorph_function
49
+ command = (super(*args))
50
+ klazz = command.instance_eval(&@@polymorph_function)
51
+ if klazz == self
52
+ super(*args)
53
+ else
54
+ klazz.new(*args)
55
+ end
56
+ else
57
+ super
58
+ end
59
+ end
43
60
  def cache(option, size: 50)
44
61
  if option
45
62
  render_method = instance_method :render
@@ -64,17 +81,24 @@ module ViewDelegates
64
81
 
65
82
  # Marks a method as a view local
66
83
  # @param [Symbol] method
67
- def view_local(method)
68
- @@view_locals << method
84
+ def view_local(*methods)
85
+ methods.each do |method|
86
+ @@view_locals << method
87
+ end
69
88
  end
70
89
 
71
90
  # View properties
72
91
  # @param [Symbol] method
73
- def property(method)
74
- @@properties << method
75
- attr_accessor method
92
+ def property(*methods)
93
+ methods.each do |method|
94
+ @@properties << method
95
+ attr_accessor method
96
+ end
76
97
  end
77
98
 
99
+ def polymorph &block
100
+ @@polymorph_function = block
101
+ end
78
102
  # The models this delegate will use
79
103
  # @param [method] method The variable name this model will use
80
104
  # @param [Array] properties The model properties to extract
@@ -1,3 +1,3 @@
1
1
  module ViewDelegates
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_delegates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Aurelio Lamas Murias