ViewComposer 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: bd8b4384af9920af4a5170465c1da6ff82fa424e
4
- data.tar.gz: 3e25d90731d18cc8e0a6d2e65e8d55e0aa83f9ad
3
+ metadata.gz: e5ce5c93cbd8b88877f158582da991558951ed51
4
+ data.tar.gz: 9381c479f662719b877733ab8fd44dd185b6c3c1
5
5
  SHA512:
6
- metadata.gz: 28531525aacedf8b0fa5ec5cd4349b551483a7ee020c3e585f90cc698df30478c405aa7a9dc8f726359266ba07921f552285e84bf43b3a6f01d4af41b0c5ca0e
7
- data.tar.gz: e2c7ed6bf365d9afd36870ea67d75c0ac818ae78a7adb4aee979e89364d47dc7de766b7ac4e3ea66539412cd9bd682bbbb60eef805f571ecaa04bb4c3538b026
6
+ metadata.gz: ade15dc7ef22e932464c2ef42f8d7111147b9053b464097cacd0df52083753684d07fb30648315d6706b3e6d43c6bd0782ca5dc60165b051df5432f7b80ca00e
7
+ data.tar.gz: a8283efa6c1a59c14f6400143b191d493aea8d53f0ccc4d64eb153260af45c83e2ffaaad848c9987a43b2e0e4a5f7aa081cffd84c3a363bce0060c743f7c0175
@@ -1,24 +1,45 @@
1
1
  require 'json'
2
- EXCLUDED_METHODS = [:to_json, :hash_attrs, :set_inherited_methods_list]
2
+ EXCLUDED_METHODS = [:to_json, :hash_attrs,
3
+ :set_inherited_methods_list,
4
+ :instance_methods,
5
+ :inherited_methods,
6
+ :attributes,
7
+ :instance_attributes,
8
+ :set_model_methods,
9
+ :super_model_methods]
3
10
  class BaseComposer
4
11
  class << self
5
- attr_accessor :_attributes, :_inherited_methods
12
+ attr_accessor :_attributes,
13
+ :_instance_attrs,
14
+ :_model_methods,
15
+ :_inherited_methods
6
16
  end
7
17
  self._attributes = []
18
+ self._instance_attrs = []
8
19
  self._inherited_methods = []
20
+ self._model_methods = []
9
21
 
10
22
  def initialize(model:, composable_objects: [] )
11
23
  set_inherited_methods_list
12
24
  @model = model
13
25
  @json_hash = {}
14
- @_attrs = self.class._attributes
15
- @inherited_methods = self.class._inherited_methods
16
- @instance_methods = self.class.instance_methods(false)
26
+ set_model_methods
17
27
  set_attributes_methods
18
28
  setup_comp_objs(composable_objects)
19
29
  methods_to_hash
20
30
  end
21
31
 
32
+ def self.attributes(*attrs)
33
+ self._instance_attrs = attrs
34
+ Array(attrs).each {|attr| self._attributes << attr}
35
+ end
36
+
37
+ def self.inherited(base)
38
+ super
39
+ base._attributes = self._attributes.dup
40
+ base._inherited_methods = self._inherited_methods.dup
41
+ end
42
+
22
43
  def hash_attrs
23
44
  @json_hash
24
45
  end
@@ -27,20 +48,43 @@ class BaseComposer
27
48
  @json_hash.to_json
28
49
  end
29
50
 
30
- def self.attributes(*attrs)
31
- Array(attrs).each {|attr| self._attributes << attr}
51
+ private
52
+
53
+ def set_model_methods
54
+ new_model_methods = attributes - instance_methods
55
+ new_model_methods = new_model_methods - inherited_methods
56
+ new_model_methods = new_model_methods + super_model_methods
57
+
58
+ if self.class.superclass != Object
59
+ self.class._model_methods = super_model_methods + new_model_methods
60
+ else
61
+ self.class._model_methods = new_model_methods
62
+ end
32
63
  end
33
64
 
34
- def self.inherited(base)
35
- super
36
- base._attributes = self._attributes.dup
37
- base._inherited_methods = self._inherited_methods.dup
65
+ def instance_attributes
66
+ @instance_attributes ||= self.class._instance_attrs || []
38
67
  end
39
68
 
40
- private
69
+ def super_model_methods
70
+ return [] if self.class.superclass === Object
71
+ @super_model ||= self.class.superclass._model_methods || []
72
+ end
73
+
74
+ def attributes
75
+ @attributes ||= self.class._attributes
76
+ end
77
+
78
+ def instance_methods
79
+ @instance_methods ||= self.class.instance_methods(false)
80
+ end
81
+
82
+ def inherited_methods
83
+ @inherted_methods ||= self.class._inherited_methods
84
+ end
41
85
 
42
86
  def get_all_methods
43
- (@_attrs + @inherited_methods + @instance_methods).uniq
87
+ (attributes + inherited_methods + instance_methods).uniq
44
88
  end
45
89
 
46
90
  def set_inherited_methods_list
@@ -60,8 +104,7 @@ private
60
104
  end
61
105
 
62
106
  def definable_methods
63
- m = @_attrs - @inherited_methods
64
- m - @instance_methods
107
+ self.class._model_methods
65
108
  end
66
109
 
67
110
  def setup_comp_objs(comp_objs_array)
@@ -79,5 +122,4 @@ private
79
122
  end
80
123
  end
81
124
  end
82
-
83
125
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComposer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ViewComposer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kory Tegman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler