Netzke::Configuration::ClassMethods

Public Instance Methods

class_config_option(name, default_value) click to toggle source

Used to define class-level configuration options for a component, e.g.:

class Netzke::Basepack::GridPanel < Netzke::Base
  class_config_option :rows_reordering_available, true
  ...
end

This can later be set in the application configuration:

module RailsApp
  class Application < Rails::Application
    config.netzke.basepack.grid_panel.rows_reordering_available = false
    ...
  end
end

Configuration options can be accessed as class attributes:

Netzke::Basepack::GridPanel.rows_reordering_available # => false
# File lib/netzke/configuration.rb, line 55
def class_config_option(name, default_value)
  value = if app_level_config.has_key?(name.to_sym)
    if app_level_config[name.to_sym].is_a?(Hash) && default_value.is_a?(Hash)
      default_value.deep_merge(app_level_config[name.to_sym])
    else
      app_level_config[name.to_sym]
    end
  else
    default_value
  end
  class_attribute(name.to_sym)
  self.send("#{name}=", value)
end
config(*args, █) click to toggle source
# File lib/netzke/configuration.rb, line 23
def config(*args, &block)
  level = args.first.is_a?(Symbol) ? args.first : :final
  config_hash = args.last.is_a?(Hash) && args.last
  raise ArgumentError, "Config hash or block required" if !block_given? && !config_hash
  if block_given?
    define_method(:"weak_#{level}_options", &block)
  else
    define_method(:"weak_#{level}_options") do
      config_hash
    end
  end
end
server_side_config_options() click to toggle source

Config options that should not go to the client side

# File lib/netzke/configuration.rb, line 19
def server_side_config_options
  [:lazy_loading, :class_name, :components]
end
setup() click to toggle source
# File lib/netzke/configuration.rb, line 14
def setup
  yield self
end

Protected Instance Methods

app_level_config() click to toggle source
# File lib/netzke/configuration.rb, line 72
def app_level_config
  @app_level_config ||= class_ancestors.inject({}) do |r,klass|
    r.deep_merge(klass.app_level_config_excluding_parents)
  end
end
app_level_config_excluding_parents() click to toggle source
# File lib/netzke/configuration.rb, line 78
def app_level_config_excluding_parents
  path_parts = name.split("::").map(&:underscore)[1..-1]
  if path_parts.present?
    path_parts.inject(Netzke::Core.config) do |r,part|
      r.send(part)
    end
  else
    {}
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.