Module: Backstage

Defined in:
lib/backstage.rb,
lib/backstage/field.rb,
lib/backstage/engine.rb,
lib/backstage/version.rb,
lib/backstage/registry.rb,
lib/backstage/configuration.rb,
lib/backstage/auto_discovery.rb,
lib/backstage/sidebar_config.rb,
lib/backstage/resource_config.rb,
lib/backstage/dashboard_config.rb,
lib/backstage/association_config.rb,
app/controllers/backstage/home_controller.rb,
app/controllers/backstage/actions_controller.rb,
app/controllers/backstage/resources_controller.rb,
app/controllers/backstage/dashboards_controller.rb,
app/controllers/backstage/application_controller.rb,
lib/generators/backstage/install/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: ActionsController, ApplicationController, AssociationConfig, AutoDiscovery, Configuration, ConfigurationError, DashboardConfig, DashboardsController, Engine, Field, HomeController, Registry, ResourceConfig, ResourcesController, SidebarConfig

Constant Summary collapse

VERSION =
"0.1.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



14
15
16
# File 'lib/backstage.rb', line 14

def configuration
  @configuration
end

.registryObject

Returns the value of attribute registry.



14
15
16
# File 'lib/backstage.rb', line 14

def registry
  @registry
end

Class Method Details

.load_configuration!(root) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/backstage.rb', line 16

def load_configuration!(root)
  path = File.join(root, "config", "backstage.yml")
  hash = File.exist?(path) ? YAML.safe_load_file(path) || {} : {}
  self.configuration = Configuration.new(hash)

  self.registry = Registry.new
  configuration.model_names.each do |name|
    begin
      model_class = name.constantize
    rescue NameError
      raise ConfigurationError, "config/backstage.yml: unknown model '#{name}'"
    end
    begin
      registry.register(name, AutoDiscovery.build(model_class))
    rescue ActiveRecord::StatementInvalid => e
      warn "Backstage: skipping #{name}#{e.message}"
      next
    end
  end

  load_dsl_files!(root)

  configuration.dashboard_configs.each do |hash|
    registry.register_dashboard(DashboardConfig.new(hash))
  end

  configuration
end

.resource(model_name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/backstage.rb', line 45

def resource(model_name)
  name = model_name.to_s
  config = registry.resource_for(name)
  yield config if block_given?
rescue KeyError
  raise ConfigurationError, "config/backstage/*.rb: no registered model '#{name}'"
end