class Enginery::Registry

Public Class Methods

new(root) click to toggle source
# File lib/enginery/registry.rb, line 5
def initialize root
  @dst_root = root.freeze
end

Public Instance Methods

controllers() click to toggle source
# File lib/enginery/registry.rb, line 9
def controllers
  boot_app
  app_controllers.inject({}) do |f,c|
    path   = controller_path(c)
    routes = routes(c)
    data   = {
        name: c.name,
        path: path,
        file: unrootify(dst_path(:controllers, path + CONTROLLER_SUFFIX)),
      dom_id: c.name.gsub(/\W/m, ''),
      routes: routes,
       specs: routes.inject(0) {|s,(_,r)| s += r[:specs].size}
    }
    helper_file = dst_path(:helpers, path + HELPER_SUFFIX)
    File.exists?(helper_file) && data[:helper_file] = unrootify(helper_file)
    f.merge c.name => data
  end.to_yaml
end
migrations(model) click to toggle source
# File lib/enginery/registry.rb, line 68
def migrations model
  migrations_by_model(model.name).inject({}) do |f,m| 
    step, time, name = m.scan(Migrator::NAME_REGEXP).flatten
    file = dst_path(:migrations, model_path(model), m)
    f.merge ('%s. %s' % [step, name.to_s.gsub('-', ' ')]) => {
      step: step,
      name: name,
      time: time,
      file: unrootify(file),
      path: file.sub(dst_path.migrations, '')
    }
  end
end
models() click to toggle source
# File lib/enginery/registry.rb, line 51
def models
  cfg = app_config()
  app_models.inject({}) do |f,m|
    path = model_path(m)
    f.merge m.name => {
             name: m.name,
             path: path,
             file: unrootify(dst_path(:models, path + MODEL_SUFFIX)),
        rear_file: rear_file(m),
        rear_path: rear_path(m, cfg),
           dom_id: m.name.gsub(/\W/m, ''),
              orm: cfg[:orm],
       migrations: migrations(m)
    }
  end.to_yaml
end
routes(controller) click to toggle source
# File lib/enginery/registry.rb, line 28
def routes controller
  path = controller_path(controller)
  routes_by_controller(controller.name).inject({}) do |f,r|
    f.merge r => {
      name:  r,
      route: controller[r.to_sym],
      file:  unrootify(dst_path(:controllers, path, r + ROUTE_SUFFIX)),
      views: views(controller, r),
      specs: specs(controller, r)
    }
  end
end
specs(controller, route) click to toggle source
# File lib/enginery/registry.rb, line 46
def specs controller, route
  path = controller_path(controller)
  Dir[dst_path(:specs, path, route + SPEC_SUFFIX)].map {|f| unrootify(f)}
end
views(controller, route) click to toggle source
# File lib/enginery/registry.rb, line 41
def views controller, route
  path = controller_path(controller)
  Dir[dst_path(:views, path, route + '.*')].map {|f| unrootify(f)}
end

Private Instance Methods

controller_path(controller) click to toggle source
# File lib/enginery/registry.rb, line 83
def controller_path controller
  EUtils.class_to_route(controller.name)
end
model_path(model) click to toggle source
# File lib/enginery/registry.rb, line 87
def model_path model
  EUtils.class_to_route(model.name)
end
rear_file(model) click to toggle source
# File lib/enginery/registry.rb, line 96
def rear_file model
  unrootify dst_path(:rear_controllers, model_path(model) + ADMIN_SUFFIX)
end
rear_path(model, cfg) click to toggle source
# File lib/enginery/registry.rb, line 91
def rear_path model, cfg
  return unless admin_url = cfg[:admin_url]
  EUtils.rootify_url(admin_url, EUtils.class_to_route(model.name))
end