lib/rails/graphql/source/builder.rb in rails-graphql-1.0.0.rc1 vs lib/rails/graphql/source/builder.rb in rails-graphql-1.0.0.rc2

- old
+ new

@@ -19,17 +19,17 @@ # Trigger a safe build of everything def build_all build_all! unless abstract? end - # Allows building anything that is in hooks + # Make sure to properly indicate about build methods def respond_to_missing?(method_name, *) return super unless method_name.to_s.start_with?('build_') && hook_names.include?(method_name.to_s[6..-1].to_sym) end - # Allow fast creation of values + # Allows all sorts of building methods to be called def method_missing(method_name, *args, **xargs, &block) return super unless method_name.to_s.start_with?('build_') type = method_name.to_s[6..-1] type = type.singularize unless hook_names.include?(type.to_sym) @@ -45,10 +45,15 @@ # Store the list of built steps def built @built ||= Set.new end + # Mark as built before running the hooks + def run_hooks(type, *) + built.add(type) + end + private # Import all options-based settings for skipping field def import_skips_for(type, options) return if type == :all @@ -91,11 +96,10 @@ end # Build all the objects associated with this source def build!(type) ensure_build!(type) - built << type schema_type = Helpers::WithSchemaFields::TYPE_FIELD_CLASS.key?(type) catch(:skip) { run_hooks(:start) } unless built?(:start) catch(:skip) { run_hooks(type, hook_scope_for(type, schema_type)) } @@ -104,10 +108,11 @@ # Get the correct +self_object+ for the hook instance def hook_scope_for(type, schema_type) type = type.to_sym klass = schema_type ? 'WithSchemaFields::ScopedConfig' : 'AttributeDelegator' - Source::ScopedConfig.new(self, Helpers.const_get(klass).new(self, type), type) + klass = Helpers.const_get(klass, false).new(self, type) + Source::ScopedConfig.new(self, klass, type) end end end end