view_composer 0.1.7 → 0.1.8

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: e46f45af2b4bd79d6069b07847b238671fcbc529
4
- data.tar.gz: da79b5d6efdd919a71ba06be34c0852735d06dd4
3
+ metadata.gz: 3134b78ce4dbd47e5a2fe59217adbde30a9c5006
4
+ data.tar.gz: f51006dee86d3513e4b81e277d1094b0360dbe6f
5
5
  SHA512:
6
- metadata.gz: bd5a7e8a0e7212138c2053d753ac8b8cb0495c5dae15c75c07b8c022980f885da0dfcb26da10c285f2d548973df6b378496ac2fc55add20269158bcf21fd6e61
7
- data.tar.gz: aa248cb57ebadb0302fa5c27cd03e340a98430cfa63e47a70db5163840eed7516afec384403cccd09bea245948e113aa60a91196aa173f5a927531be6d3cda57
6
+ metadata.gz: cfbb157f321453a582e5c03f365d5e05b55e928b9a52099a29623de93e1b08f356a8b4306a0b3d6ddc32d77352d430e2107016bd39ddc713f9dc4dcfd6b73752
7
+ data.tar.gz: 31c212080adbe9e6be5ab0dbf91962dfd575abccf7b9ab2e142d722f83d86923a39bd60af7edd0ba2f6890bc81061bf0aa820917d25816064fb874573224162c
@@ -1,47 +1,31 @@
1
1
  require 'json'
2
2
  EXCLUDED_METHODS = [:to_json, :hash_attrs,
3
- :set_inherited_methods_list,
4
- :instance_methods,
5
- :inherited_methods,
6
3
  :attributes,
7
- :instance_attributes,
8
- :set_model_methods,
9
- :super_model_methods]
4
+ :definable_model_methods]
10
5
  module ViewComposer
11
6
  class BaseComposer
12
7
  class << self
13
- attr_accessor :_attributes,
14
- :_instance_attrs,
15
- :_model_methods,
16
- :_instance_defined_methods,
17
- :_inherited_methods
8
+ attr_accessor :_attributes
18
9
  end
19
10
  self._attributes = []
20
- self._instance_attrs = []
21
- self._inherited_methods = []
22
- self._model_methods = []
23
11
 
24
12
  def initialize(model:, composable_objects: [] )
25
- set_inherited_methods_list
26
13
  @model = model
27
14
  @json_hash = {}
15
+
28
16
  set_model_methods
29
- set_instance_defined_methods
30
17
  set_attributes_methods
31
18
  setup_comp_objs(composable_objects)
32
19
  methods_to_hash
33
20
  end
34
21
 
35
22
  def self.attributes(*attrs)
36
- self._instance_attrs = attrs
37
23
  Array(attrs).each {|attr| self._attributes << attr}
38
24
  end
39
25
 
40
26
  def self.inherited(base)
41
27
  super
42
28
  base._attributes = self._attributes.dup
43
- base._inherited_methods = self._inherited_methods.dup
44
- base._model_methods = self._model_methods.dup
45
29
  end
46
30
 
47
31
  def hash_attrs
@@ -55,32 +39,8 @@ module ViewComposer
55
39
  private
56
40
 
57
41
  def set_model_methods
58
- new_model_methods = attributes - instance_methods
59
- new_model_methods = new_model_methods - inherited_methods
60
- new_model_methods = new_model_methods + super_model_methods
61
-
62
- if self.class.superclass != Object
63
- self.class._model_methods = super_model_methods + new_model_methods
64
- else
65
- self.class._model_methods = new_model_methods
66
- end
67
- end
68
-
69
- def set_instance_defined_methods
70
- if self.class._instance_defined_methods != nil
71
- self.class._instance_defined_methods += self.class._model_methods
72
- else
73
- self.class._instance_defined_methods = self.class._model_methods
74
- end
75
- end
76
-
77
- def instance_attributes
78
- @instance_attributes ||= self.class._instance_attrs || []
79
- end
80
-
81
- def super_model_methods
82
- return [] if self.class.superclass === Object
83
- @super_model ||= self.class.superclass._model_methods || []
42
+ new_model_methods = attributes - self.methods
43
+ set_model_methods_array(new_model_methods)
84
44
  end
85
45
 
86
46
  def attributes
@@ -91,17 +51,8 @@ module ViewComposer
91
51
  @instance_methods ||= self.class.instance_methods(false)
92
52
  end
93
53
 
94
- def inherited_methods
95
- @inherted_methods ||= self.class._inherited_methods
96
- end
97
-
98
54
  def get_all_methods
99
- (attributes + inherited_methods + instance_methods).uniq
100
- end
101
-
102
- def set_inherited_methods_list
103
- _methods = self.class.superclass.instance_methods(false) - EXCLUDED_METHODS
104
- self.class._inherited_methods += _methods
55
+ (attributes + instance_methods).uniq
105
56
  end
106
57
 
107
58
  def methods_to_hash
@@ -111,12 +62,19 @@ module ViewComposer
111
62
  end
112
63
  end
113
64
 
114
- def set_attributes_methods
115
- define_methods(definable_methods, @model)
65
+ def definable_model_methods
66
+ []
116
67
  end
117
68
 
118
- def definable_methods
119
- self.class._instance_defined_methods + self.class._model_methods
69
+ def set_model_methods_array(new_model_methods)
70
+ dup_of_methods = definable_model_methods.dup
71
+ self.class.send(:define_method, "definable_model_methods") do
72
+ (dup_of_methods + new_model_methods).uniq
73
+ end
74
+ end
75
+
76
+ def set_attributes_methods
77
+ define_methods(definable_model_methods, @model)
120
78
  end
121
79
 
122
80
  def setup_comp_objs(comp_objs_array)
@@ -129,7 +87,7 @@ module ViewComposer
129
87
 
130
88
  def define_methods(method_names, method_owner)
131
89
  method_names.uniq.each do |attr|
132
- self.class.send(:define_method, attr) do
90
+ send(:define_singleton_method, attr) do
133
91
  method_owner.send(attr)
134
92
  end
135
93
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComposer
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_composer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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-10 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler