Class: TorqueBox::Configuration::Entry Private

Inherits:
BlankSlate
  • Object
show all
Defined in:
lib/torquebox/configuration.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

OptionsEntry, ThingWithOptionsEntry, ThingsEntry

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, entry_map, options = { }) ⇒ Entry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Entry.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/torquebox/configuration.rb', line 39

def initialize(name, config, entry_map, options = { })
  @name = name
  @config = config
  @entry_map = entry_map
  @parents = options.delete( :parents ) || []
  @options = options
  @line_number = find_line_number
  @entry_options = { }
  
  if options[:require_parent] && ([options[:require_parent]].flatten & @parents).empty?
    raise ConfigurationError.new( "#{@name} only allowed inside #{options[:require_parent]}", @line_number )
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
107
108
109
110
111
112
# File 'lib/torquebox/configuration.rb', line 104

def method_missing(method, *args, &block)
  klass = @entry_map[method]
  if klass
    entry = klass.new( method, @entry_options, @entry_map, :parents => @parents + [@name] )
    entry.process( *args, &block )
  else
    add_options( method.to_sym => args.first )
  end
end

Class Method Details

.const_missing(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
# File 'lib/torquebox/configuration.rb', line 84

def self.const_missing(name)
  FakeConstant.new( name ).to_const
end

.with_settings(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/torquebox/configuration.rb', line 88

def self.with_settings(options)
  klass = self
  proxy = Object.new
  (class << proxy; self; end).__send__( :define_method, :new ) do |*args|
    if args.last.is_a?( Hash )
      args.last.merge!( options )
    else
      args << options
    end
    klass.new( *args )
  end
  proxy
end

Instance Method Details

#add_options(option) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



114
115
116
# File 'lib/torquebox/configuration.rb', line 114

def add_options( option )
  @entry_options.merge!( option )
end

#eval_block(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



80
81
82
# File 'lib/torquebox/configuration.rb', line 80

def eval_block(&block)
  block.arity < 1 ? self.instance_eval( &block ) : block.call( self )
end

#finalize_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



118
119
120
121
122
123
124
125
# File 'lib/torquebox/configuration.rb', line 118

def finalize_options
  if @options[:discrete]
    local_config << @entry_options
  else
    @entry_options = local_config.merge!( @entry_options )
  end
  local_config
end

#find_line_numberObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
# File 'lib/torquebox/configuration.rb', line 53

def find_line_number
  caller.each do |line|
    return $1 if line =~ /\(eval\):(\d+):/
  end
  nil
end

#local_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



127
128
129
130
# File 'lib/torquebox/configuration.rb', line 127

def local_config
  @config[@name.to_s] = [] if @options[:discrete] && !@config[@name.to_s].is_a?(Array)
  @config[@name.to_s] ||= {}  
end

#local_config=(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/torquebox/configuration.rb', line 132

def local_config=(value)
  @config[@name.to_s] = value
end

#process(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
# File 'lib/torquebox/configuration.rb', line 60

def process(*args, &block)
  process_args( args )
  eval_block( &block ) if block_given?
  validate_options
  finalize_options
  local_config
end

#process_args(unused) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
# File 'lib/torquebox/configuration.rb', line 68

def process_args(unused)
  # no op
  @config
end

#validate_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
# File 'lib/torquebox/configuration.rb', line 73

def validate_options
  if @options[:validate]
    validator = Validator.new( @options[:validate], @name, @entry_options )
    raise ConfigurationError.new( validator.message, @line_number ) unless validator.valid?
  end
end