Class: TorqueBox::Configuration::Entry Private
- Inherits:
-
BlankSlate
- Object
- BlankSlate
- TorqueBox::Configuration::Entry
- 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
Class Method Summary collapse
- .const_missing(name) ⇒ Object private
- .with_settings(options) ⇒ Object private
Instance Method Summary collapse
- #add_options(option) ⇒ Object private
- #eval_block(&block) ⇒ Object private
- #finalize_options ⇒ Object private
- #find_line_number ⇒ Object private
-
#initialize(name, config, entry_map, options = { }) ⇒ Entry
constructor
private
A new instance of Entry.
- #local_config ⇒ Object private
- #local_config=(value) ⇒ Object private
- #method_missing(method, *args, &block) ⇒ Object private
- #process(*args, &block) ⇒ Object private
- #process_args(unused) ⇒ Object private
- #validate_options ⇒ Object private
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, = { }) @name = name @config = config @entry_map = entry_map @parents = .delete( :parents ) || [] @options = @line_number = find_line_number @entry_options = { } if [:require_parent] && ([[:require_parent]].flatten & @parents).empty? raise ConfigurationError.new( "#{@name} only allowed inside #{[: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 ( 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() klass = self proxy = Object.new (class << proxy; self; end).__send__( :define_method, :new ) do |*args| if args.last.is_a?( Hash ) args.last.merge!( ) else args << 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 ( 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_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.
118 119 120 121 122 123 124 125 |
# File 'lib/torquebox/configuration.rb', line 118 def if @options[:discrete] local_config << @entry_options else @entry_options = local_config.merge!( @entry_options ) end local_config end |
#find_line_number ⇒ 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.
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_config ⇒ 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.
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? 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_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.
73 74 75 76 77 78 |
# File 'lib/torquebox/configuration.rb', line 73 def if @options[:validate] validator = Validator.new( @options[:validate], @name, @entry_options ) raise ConfigurationError.new( validator., @line_number ) unless validator.valid? end end |