ViewComposer 0.1.1 → 0.1.2

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: e01710912069f547c2f251e819955b4dfdf76c2c
4
- data.tar.gz: 15315b3fcdc08e1cd8ef1f43afd23f35f9adce13
3
+ metadata.gz: bd8b4384af9920af4a5170465c1da6ff82fa424e
4
+ data.tar.gz: 3e25d90731d18cc8e0a6d2e65e8d55e0aa83f9ad
5
5
  SHA512:
6
- metadata.gz: de0ded3689cf1873e8c08dff447c262f94645720cf7bae67d1090a920d1be3445eec8259cda3f22f0e2e5e49d9352648e848bc25b6171b77d4f8392c6c748771
7
- data.tar.gz: 2fbf89468409977c0f009eb7c0e3fa3719c04a23d867dd568bca11ca613e0674102eb1bcbac02fbc01e26e58addbf7288945431a345d2f074a2386f886b1692d
6
+ metadata.gz: 28531525aacedf8b0fa5ec5cd4349b551483a7ee020c3e585f90cc698df30478c405aa7a9dc8f726359266ba07921f552285e84bf43b3a6f01d4af41b0c5ca0e
7
+ data.tar.gz: e2c7ed6bf365d9afd36870ea67d75c0ac818ae78a7adb4aee979e89364d47dc7de766b7ac4e3ea66539412cd9bd682bbbb60eef805f571ecaa04bb4c3538b026
@@ -1,19 +1,20 @@
1
1
  require 'json'
2
+ EXCLUDED_METHODS = [:to_json, :hash_attrs, :set_inherited_methods_list]
2
3
  class BaseComposer
3
4
  class << self
4
- attr_accessor :_attributes
5
+ attr_accessor :_attributes, :_inherited_methods
5
6
  end
6
7
  self._attributes = []
8
+ self._inherited_methods = []
7
9
 
8
10
  def initialize(model:, composable_objects: [] )
11
+ set_inherited_methods_list
9
12
  @model = model
10
13
  @json_hash = {}
11
-
12
- @parent_methods = self.class.superclass.instance_methods(false)
13
- @composer_methods = self.class.instance_methods(false)
14
- @dont_redefine = @parent_methods + @composer_methods
15
14
  @_attrs = self.class._attributes
16
- set_attributes
15
+ @inherited_methods = self.class._inherited_methods
16
+ @instance_methods = self.class.instance_methods(false)
17
+ set_attributes_methods
17
18
  setup_comp_objs(composable_objects)
18
19
  methods_to_hash
19
20
  end
@@ -33,21 +34,34 @@ class BaseComposer
33
34
  def self.inherited(base)
34
35
  super
35
36
  base._attributes = self._attributes.dup
37
+ base._inherited_methods = self._inherited_methods.dup
36
38
  end
37
39
 
38
40
  private
39
41
 
42
+ def get_all_methods
43
+ (@_attrs + @inherited_methods + @instance_methods).uniq
44
+ end
45
+
46
+ def set_inherited_methods_list
47
+ _methods = self.class.superclass.instance_methods(false) - EXCLUDED_METHODS
48
+ self.class._inherited_methods += _methods
49
+ end
50
+
40
51
  def methods_to_hash
41
- methods = self.class.instance_methods(false) - [:to_json, :hash_attrs]
52
+ methods = get_all_methods - EXCLUDED_METHODS
42
53
  methods.each do |method|
43
54
  @json_hash[method] = self.send(method)
44
55
  end
45
56
  end
46
57
 
47
- def set_attributes
48
- defineable_methods = @_attrs - @dont_redefine
49
- #puts "#{self}: #{defineable_methods}"
50
- define_methods(defineable_methods, @model)
58
+ def set_attributes_methods
59
+ define_methods(definable_methods, @model)
60
+ end
61
+
62
+ def definable_methods
63
+ m = @_attrs - @inherited_methods
64
+ m - @instance_methods
51
65
  end
52
66
 
53
67
  def setup_comp_objs(comp_objs_array)
@@ -61,7 +75,6 @@ private
61
75
  def define_methods(method_names, method_owner)
62
76
  method_names.each do |attr|
63
77
  self.class.send(:define_method, attr) do
64
- #puts method_owner.send(attr)
65
78
  method_owner.send(attr)
66
79
  end
67
80
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComposer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-05 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler