Module: Izzle::HasEasy::ClassMethods

Defined in:
lib/has_easy.rb

Instance Method Summary collapse

Instance Method Details

#has_easy(context = nil, options = {}) {|configurator| ... } ⇒ Object

Yields:

  • (configurator)

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/has_easy.rb', line 19

def has_easy(context = nil, options = {})
  context = Helpers.normalize(context)
  
  # initialize the class instance var to hold our configuration info
  class << self
    attr_accessor :has_easy_configurators unless method_defined?(:has_easy_configurators)
  end
  self.has_easy_configurators = {} if self.has_easy_configurators.nil?
  
  # don't let the user redefine a context
  raise ArgumentError, "class #{self} already has_easy('#{context}')" if self.has_easy_configurators.has_key?(context)
  
  
  
  configurator = Configurator.new(self, context, options)
  yield configurator
  configurator.do_metaprogramming_magic_aka_define_methods
  has_easy_configurators[context] = configurator
end