Class: Enginery::Registry

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/enginery/registry.rb

Instance Method Summary collapse

Methods included from Helpers

#activerecord_associations, #app_config, #app_controllers, #app_models, #boot_app, #controller_exists?, #datamapper_associations, #dst_path, extract_setup, fail, #fail_unless_in_app_folder!, fail_verbosely, #in_app_folder?, #load_boot_rb, #migrations_by_model, #model_exists?, o, parse_input, #routes_by_controller, #sequel_associations, #src_path, #unrootify, #valid_controller?, valid_db_type?, valid_engine?, valid_orm?, #valid_route?, valid_server?, validate_constant_name, #validate_route_name, #view_setups_for

Constructor Details

#initialize(root) ⇒ Registry

Returns a new instance of Registry.



5
6
7
# File 'lib/enginery/registry.rb', line 5

def initialize root
  @dst_root = root.freeze
end

Instance Method Details

#controllersObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/enginery/registry.rb', line 9

def controllers
  boot_app
  app_controllers.inject({}) do |f,c|
    path   = EUtils.class_to_route(c.name)
    routes = routes_by_controller(c.name).inject({}) do |f,r|
      f.merge r => {
        name: r,
        route: c[r.to_sym],
        file: unrootify(dst_path(:controllers, path, r + ROUTE_SUFFIX)),
        views: Dir[dst_path(:views, path, r + '.*')].map {|f| unrootify(f)},
        specs: Dir[dst_path(:specs, path, r + SPEC_SUFFIX)].map {|f| unrootify(f)}
      }
    end
    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,(n,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

#modelsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/enginery/registry.rb', line 36

def models
  cfg = app_config()
  app_models.inject({}) do |f,c|
    path = EUtils.class_to_route(c.name)
    migrations = migrations_by_model(c.name).inject({}) do |f,m| 
      step, time, name = m.scan(Migrator::NAME_REGEXP).flatten
      file = dst_path(:migrations, path, 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
    
    admin_url = cfg[:admin_url]
    rear_path = admin_url && EUtils.rootify_url(admin_url, EUtils.class_to_route(c.name))

    f.merge c.name => {
      name: c.name,
      path: path,
      file: unrootify(dst_path(:models, path + MODEL_SUFFIX)),
      rear_file: unrootify(dst_path(:rear_controllers, path + ADMIN_SUFFIX)),
      rear_path: rear_path,
      dom_id: c.name.gsub(/\W/m, ''),
      orm: cfg[:orm],
      migrations: migrations
    }
  end.to_yaml
end