class Migrant::SchemaProxy
Why does this class exist? Excellent question. Basically, Kernel gives a whole bunch of global methods, like system, puts, etc. This is bad because our DSL relies on being able to translate any arbitrary method into a method_missing
call. So, we call method missing in this happy bubble where these magic methods don't exist. The reason we don't inherit Schema
itself in this way, is that we'd lose direct access to all other classes derived from Object. Normally this would just mean scope resolution operators all over the class, but the real killer is that the DSL would need to reference classes in that manner as well, which would reduce sexy factor by at least 100.
Public Class Methods
# File lib/migrant/schema.rb, line 121 def initialize(binding) @binding = binding end
Public Instance Methods
# File lib/migrant/schema.rb, line 134 def method_missing(*args, &block) field = args.slice!(0) data_type = args.slice!(0) unless args.first.nil? || args.first.respond_to?(:keys) @binding.add_field(field.to_sym, data_type, args.extract_options!) end
Provides a method for dynamically creating fields (i.e. not part of instance_eval)
# File lib/migrant/schema.rb, line 130 def property(*arguments) method_missing(*arguments) end
# File lib/migrant/schema.rb, line 125 def translate_fancy_dsl(&block) self.instance_eval(&block) end