Class: Releaf::Builders
  
  
  
  
  
    - Inherits:
 
    - 
      Object
      
        
        show all
      
    
 
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - app/builders/releaf/builders.rb
 
  
  
 
Defined Under Namespace
  
    
      Modules: Base, Collection, Page, Resource, ResourceDialog, ResourceView, Template, Toolbox, Utilities, View
    
  
    
      Classes: AssociationReflector, ConfirmDestroyDialogBuilder, ConfirmDialogBuilder, EditBuilder, FormBuilder, IndexBuilder, PaginationBuilder, RefusedDestroyDialogBuilder, ShowBuilder, TableBuilder, ToolboxBuilder
    
  
  
    
      Class Method Summary
      collapse
    
    
  
  
    Class Method Details
    
      
  
  
    .builder_class(scopes, type)  ⇒ Object 
  
  
  
  
    
      
2
3
4
5
6
7
8
9 
     | 
    
      # File 'app/builders/releaf/builders.rb', line 2
def self.builder_class(scopes, type)
  (scopes + inherited_builder_scopes).each do |scope|
    builder_class = builder_class_at_scope(scope, type)
    return builder_class if builder_class
  end
  raise ArgumentError, "unexisting builder (type: #{type}; scopes: #{scopes.join(", ")})"
end
     | 
  
 
    
      
  
  
    .builder_class_at_scope(scope, type)  ⇒ Object 
  
  
  
  
    
      
11
12
13
14
15
16
17 
     | 
    
      # File 'app/builders/releaf/builders.rb', line 11
def self.builder_class_at_scope(scope, type)
  builder_class_name = "#{scope}::#{type.to_s.camelize}Builder"
  if constant_defined_at_scope?(scope, Object) && constant_defined_at_scope?(builder_class_name, scope.constantize)
    builder_class_name.constantize
  end
end
     | 
  
 
    
      
  
  
    .constant_defined_at_scope?(mapping, at)  ⇒ Boolean 
  
  
  
  
    
      
19
20
21
22
23
24
25
26
27
28
29 
     | 
    
      # File 'app/builders/releaf/builders.rb', line 19
def self.constant_defined_at_scope?(mapping, at)
  constant_defined = false
  begin
    constant_defined = at.const_get(mapping).present? && mapping.constantize == at.const_get(mapping)
  rescue NameError => error
    raise unless constant_name_error?(error.message, mapping)
  end
  constant_defined
end
     | 
  
 
    
      
  
  
    .constant_name_error?(error_message, mapping)  ⇒ Boolean 
  
  
  
  
    
      
31
32
33 
     | 
    
      # File 'app/builders/releaf/builders.rb', line 31
def self.constant_name_error?(error_message, mapping)
  (error_message =~ /#{mapping}$/).present?
end
     | 
  
 
    
      
  
  
    .inherited_builder_scopes  ⇒ Object 
  
  
  
  
    
      
35
36
37 
     | 
    
      # File 'app/builders/releaf/builders.rb', line 35
def self.inherited_builder_scopes
  (ancestors.grep(Class) - [Object, BasicObject]).collect{|c| c.name }
end
     |