Class: Migrant::SchemaProxy
- Inherits:
- BasicObject
- Defined in:
- lib/migrant/schema.rb
Overview
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.
Instance Method Summary collapse
-
#initialize(binding) ⇒ SchemaProxy
constructor
A new instance of SchemaProxy.
- #method_missing(*args, &block) ⇒ Object
-
#property(*arguments) ⇒ Object
Provides a method for dynamically creating fields (i.e. not part of instance_eval).
- #translate_fancy_dsl(&block) ⇒ Object
Constructor Details
#initialize(binding) ⇒ SchemaProxy
Returns a new instance of SchemaProxy.
121 122 123 |
# File 'lib/migrant/schema.rb', line 121 def initialize(binding) @binding = binding end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
134 135 136 137 138 139 |
# 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.) end |
Instance Method Details
#property(*arguments) ⇒ Object
Provides a method for dynamically creating fields (i.e. not part of instance_eval)
130 131 132 |
# File 'lib/migrant/schema.rb', line 130 def property(*arguments) method_missing(*arguments) end |
#translate_fancy_dsl(&block) ⇒ Object
125 126 127 |
# File 'lib/migrant/schema.rb', line 125 def translate_fancy_dsl(&block) self.instance_eval(&block) end |