Module: Settings::InstanceLevel::ClassMethods

Defined in:
lib/iron/settings/instance_level.rb

Overview

Will be bound to Object, provides support for defining settings structure + defaults at the class level for use in instances of that class. Defaults to database-backed dynamic storage with a 10 second reload. Requires that ActiveRecord be required prior to requiring this gem.

Instance Method Summary collapse

Instance Method Details

#instance_settings(options = {}, &block) ⇒ Object



11
12
13
14
15
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
44
45
46
# File 'lib/iron/settings/instance_level.rb', line 11

def instance_settings(options = {}, &block)
  unless @settings_instance_root
    @settings_instance_root = Settings::Root.new()
    @options = {
      :store => :dynamic
    }.merge(options)
  end

  # Set our default reload timing
  if options[:reload].nil?
    if options[:store] == :static
      # Static settings generally don't need reloading
      options[:reload] = false
    else
      # For dynamic, db-backed settings at the instance level, we use
      # a 10 second timeout by default
      options[:reload] = 10
    end
  end

  # Save off our options
  @settings_instance_options = options

  # This class now need settings support at the instance level
  include InstanceMethods

  # Add our save hook if the class is an ActiveRecord model
  if defined?(ActiveRecord) && self < ActiveRecord::Base
    after_save :settings_save!
  end

  # Construct a builder and do the right thing
  builder = Settings::Builder.new(@settings_instance_root)
  builder.define(&block) if block
  builder
end

#settings_instance_optionsObject



48
49
50
# File 'lib/iron/settings/instance_level.rb', line 48

def settings_instance_options
  @settings_instance_options
end

#settings_instance_rootObject



52
53
54
# File 'lib/iron/settings/instance_level.rb', line 52

def settings_instance_root
  @settings_instance_root
end