diff --git a/spec/habitat_spec.cr b/spec/habitat_spec.cr index 64ea804..c8de67b 100644 --- a/spec/habitat_spec.cr +++ b/spec/habitat_spec.cr @@ -23,6 +23,12 @@ class FakeServer end end +class Generics < Hash(String, String) + Habitat.create do + setting should_work : String = "with generics" + end +end + class Parent Habitat.create do setting parent_setting : Bool = true @@ -98,6 +104,10 @@ describe Habitat do FakeServer.configure { |settings| settings.nilable_with_default = nil } FakeServer.settings.nilable_with_default.should be_nil end + + it "works with generics" do + Generics.settings.should_work.should eq "with generics" + end it "can set and reset config using a block" do setup_server(port: 3000) diff --git a/src/habitat.cr b/src/habitat.cr index 94b0dd4..74c8524 100644 --- a/src/habitat.cr +++ b/src/habitat.cr @@ -164,7 +164,7 @@ class Habitat end macro inherit_habitat_settings_from_superclass - {% if @type.superclass && @type.superclass.constant(:HABITAT_SETTINGS) %} + {% if @type.superclass && @type.superclass.type_vars.size == 0 && @type.superclass.constant(:HABITAT_SETTINGS) %} {% for decl in @type.superclass.constant(:HABITAT_SETTINGS) %} {% HABITAT_SETTINGS << decl %} {% end %} @@ -177,7 +177,7 @@ class Habitat {% type_with_habitat = type_with_habitat.resolve %} class Settings - {% if type_with_habitat.superclass && type_with_habitat.superclass.constant(:HABITAT_SETTINGS) %} + {% if type_with_habitat.superclass && type_with_habitat.superclass.type_vars.size == 0 && type_with_habitat.superclass.constant(:HABITAT_SETTINGS) %} {% for decl in type_with_habitat.superclass.constant(:HABITAT_SETTINGS).map { |setting| setting[:decl] } %} def self.{{ decl.var }} ::{{ type_with_habitat.superclass }}::Settings.{{ decl.var }}