ViewComposer 0.0.1 → 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 +4 -4
- data/.rspec +1 -1
- data/lib/ViewComposer/base_composer.rb +21 -21
- data/lib/ViewComposer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 336035687d6fa286eec62a0435eda547764ee858
|
4
|
+
data.tar.gz: 9e6a4ee0f9c9962fccc6109eade59ef5017870ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24a3bb451d252802e4851cc673332c60ac67576a35b7857624a10347f5aa67a505c31f5f8ffd889c5e81a7ba8f626e093c7e2e7e9fcc8046bd4f2654cd00bba4
|
7
|
+
data.tar.gz: e99e8f56e587c443744063d04753dd9f536feae1f78c63ee7ee34fec1a46a98d42c2342573cfe406113e717360f31c7a0154d130cf1c6516b7f2035832ce2039
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
@@ -1,12 +1,16 @@
|
|
1
1
|
require 'json'
|
2
2
|
class BaseComposer
|
3
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :_attributes
|
5
|
+
end
|
6
|
+
self._attributes = []
|
7
|
+
|
4
8
|
def initialize(model:, composable_objects: [] )
|
5
|
-
#self.class.attributes
|
6
9
|
@model = model
|
7
|
-
@composer_methods = self.class.instance_methods(false)
|
8
10
|
@json_hash = {}
|
9
|
-
|
11
|
+
@composer_methods = self.class.instance_methods(false)
|
12
|
+
@_attrs = self.class._attributes
|
13
|
+
set_attributes
|
10
14
|
setup_comp_objs(composable_objects)
|
11
15
|
methods_to_hash
|
12
16
|
end
|
@@ -19,29 +23,17 @@ class BaseComposer
|
|
19
23
|
@json_hash.to_json
|
20
24
|
end
|
21
25
|
|
22
|
-
def self.attributes(*
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.get_attributes
|
27
|
-
@attributes || []
|
26
|
+
def self.attributes(*attrs)
|
27
|
+
Array(attrs).each {|attr| self._attributes << attr}
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.inherited(base)
|
31
31
|
super
|
32
|
-
|
32
|
+
base._attributes = self._attributes.dup
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
-
def define_methods(method_names, method_owner)
|
38
|
-
method_names.each do |attr|
|
39
|
-
self.class.send(:define_method, attr) do
|
40
|
-
method_owner.send(attr)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
37
|
def methods_to_hash
|
46
38
|
methods = self.class.instance_methods(false) - [:to_json, :hash_attrs]
|
47
39
|
methods.each do |method|
|
@@ -49,8 +41,8 @@ private
|
|
49
41
|
end
|
50
42
|
end
|
51
43
|
|
52
|
-
def set_attributes
|
53
|
-
defineable_methods =
|
44
|
+
def set_attributes
|
45
|
+
defineable_methods = @_attrs - @composer_methods
|
54
46
|
define_methods(defineable_methods, @model)
|
55
47
|
end
|
56
48
|
|
@@ -62,4 +54,12 @@ private
|
|
62
54
|
end
|
63
55
|
end
|
64
56
|
|
57
|
+
def define_methods(method_names, method_owner)
|
58
|
+
method_names.each do |attr|
|
59
|
+
self.class.send(:define_method, attr) do
|
60
|
+
method_owner.send(attr)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
65
|
end
|
data/lib/ViewComposer/version.rb
CHANGED