From 1a9b7572f3e3cde0e737dcf4bc35aeb83331a004 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Sun, 28 Feb 2021 20:14:43 -0500
Subject: [PATCH] defaults fix.

---
 lib/aethyr/core/util/defaults.rb | 45 +++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 7 deletions(-)

diff --git a/lib/aethyr/core/util/defaults.rb b/lib/aethyr/core/util/defaults.rb
index 1a03839..11dff61 100644
--- a/lib/aethyr/core/util/defaults.rb
+++ b/lib/aethyr/core/util/defaults.rb
@@ -1,14 +1,12 @@
 module Defaults
   @@defaults = {}
 
-  def self.default(attribute_raw, &block)
-    default_exists = @@defaults.key? self.name.to_s
-    local_defaults = default_exists ? @@defaults[self.name.to_s] : []
-
-    attribute = "@".concat(attribute_raw.to_s).to_sym
+  def self.defaults
+    @@defaults
+  end
 
-    local_defaults.push({:attribute => attribute, :block => block})
-    @@defaults[self.name.to_s] = local_defaults if not default_exists
+  def self.included(klazz)
+    klazz.extend(ClassMethods)
   end
 
   def load_defaults
@@ -28,4 +26,37 @@ module Defaults
   def set_default(attribute)
     self.set_instance_variable(attribute, yield)
   end
+
+  module ClassMethods
+    def default(attribute_raw, &block)
+      default_exists = Defaults.defaults.key? self.name.to_s
+      local_defaults = default_exists ? Defaults.defaults[self.name.to_s] : []
+
+      attribute = "@".concat(attribute_raw.to_s).to_sym
+
+      local_defaults.push({:attribute => attribute, :block => block})
+      Defaults.defaults[self.name.to_s] = local_defaults if not default_exists
+    end
+  end
+end
+
+class Foo
+  include Defaults
+  default(:bar) {"foobar"}
+
+  def initialize
+    load_defaults
+  end
+
+  def bar
+    @bar
+  end
+
+  def self.check_df
+    @@defaults
+  end
+
+  def local_df
+    @@defaults
+  end
 end
-- 
GitLab