Class: Peony::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/peony/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



5
6
7
# File 'lib/peony/settings.rb', line 5

def initialize
  @current_scope = @root_scope = Scope.new(:root)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/peony/settings.rb', line 19

def method_missing(method, *args, &block)
  if current_scope.respond_to?(method, false)
    current_scope.__send__(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#current_scopeObject (readonly)

Returns the value of attribute current_scope.



3
4
5
# File 'lib/peony/settings.rb', line 3

def current_scope
  @current_scope
end

#root_scopeObject (readonly)

Returns the value of attribute root_scope.



3
4
5
# File 'lib/peony/settings.rb', line 3

def root_scope
  @root_scope
end

Instance Method Details

#respond_to_missing?(method, include_all = true) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/peony/settings.rb', line 27

def respond_to_missing?(method, include_all = true)
  current_scope.respond_to?(method, include_all)
end

#with_scope(name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/peony/settings.rb', line 9

def with_scope(name)
  original_scope = current_scope
  begin
    @current_scope = original_scope.new_scope(name)
    yield
  ensure
    @current_scope = original_scope
  end
end