Class: Navy::Orders
- Inherits:
-
Object
- Object
- Navy::Orders
- Defined in:
- lib/navy/orders.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
- #defaults ⇒ Object
-
#rank_class ⇒ Object
readonly
Returns the value of attribute rank_class.
-
#set ⇒ Object
Returns the value of attribute set.
Class Method Summary collapse
-
.defaults ⇒ Object
class_attribute :defaults ##.
- .defaults=(val) ⇒ Object
- .defaults? ⇒ Boolean
- .inherited(base) ⇒ Object
Instance Method Summary collapse
-
#[](key) ⇒ Object
:nodoc:.
- #defaults? ⇒ Boolean
- #give!(rank, options = {}) ⇒ Object
-
#initialize(rank_class, options = {}) ⇒ Orders
constructor
A new instance of Orders.
-
#reload(merge_defaults = true) ⇒ Object
:nodoc:.
- #sailor_mouth ⇒ Object
Constructor Details
#initialize(rank_class, options = {}) ⇒ Orders
Returns a new instance of Orders.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/navy/orders.rb', line 42 def initialize(rank_class, = {}) @rank_class = rank_class self.set = Hash.new(:unset) self.config_file = .delete(:config_file) @use_defaults = .delete(:use_defaults) set.merge!(defaults) if @use_defaults .each { |key, value| sailor_mouth.__send__(key, value) } reload(false) end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
40 41 42 |
# File 'lib/navy/orders.rb', line 40 def config_file @config_file end |
#defaults ⇒ Object
20 21 22 |
# File 'lib/navy/orders.rb', line 20 def defaults defined?(@defaults) ? @defaults : self.class.defaults end |
#rank_class ⇒ Object (readonly)
Returns the value of attribute rank_class.
39 40 41 |
# File 'lib/navy/orders.rb', line 39 def rank_class @rank_class end |
#set ⇒ Object
Returns the value of attribute set.
40 41 42 |
# File 'lib/navy/orders.rb', line 40 def set @set end |
Class Method Details
.defaults ⇒ Object
class_attribute :defaults ##
4 |
# File 'lib/navy/orders.rb', line 4 def self.defaults; nil; end |
.defaults=(val) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/navy/orders.rb', line 6 def self.defaults=(val) singleton_class.class_eval do begin if method_defined?(:defaults) || private_method_defined?(:defaults) remove_method(:defaults) end rescue NameError # ignore this end define_method(:defaults) { val } end val end |
.defaults? ⇒ Boolean
5 |
# File 'lib/navy/orders.rb', line 5 def self.defaults?; !!defaults; end |
.inherited(base) ⇒ Object
35 36 37 |
# File 'lib/navy/orders.rb', line 35 def self.inherited(base) base.defaults = self.defaults.dup end |
Instance Method Details
#[](key) ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/navy/orders.rb', line 93 def [](key) # :nodoc: set[key] end |
#defaults? ⇒ Boolean
23 24 25 |
# File 'lib/navy/orders.rb', line 23 def defaults? !!defaults end |
#give!(rank, options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/navy/orders.rb', line 79 def give!(rank, = {}) only = [:only] || [] except = [:except] || (only.empty? ? [] : set.keys - only) set.each do |key, value| value == :unset and next except.include?(key) and next rank.__send__("#{key}=", value) end end |
#reload(merge_defaults = true) ⇒ Object
:nodoc:
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/navy/orders.rb', line 54 def reload(merge_defaults = true) #:nodoc: if merge_defaults && @use_defaults set.merge!(defaults) if @use_defaults end sailor_mouth.curse!(config_file) if config_file # instance_eval(File.read(config_file), config_file) if config_file # parse_rackup_file # RACKUP[:set_listener] and # set[:listeners] << "#{RACKUP[:host]}:#{RACKUP[:port]}" # # unicorn_rails creates dirs here after working_directory is bound # after_reload.call if after_reload # # working_directory binds immediately (easier error checking that way), # # now ensure any paths we changed are correctly set. # [ :pid, :stderr_path, :stdout_path ].each do |var| # String === (path = set[var]) or next # path = File.expand_path(path) # File.writable?(path) || File.writable?(File.dirname(path)) or \ # raise ArgumentError, "directory for #{var}=#{path} not writable" # end end |
#sailor_mouth ⇒ Object
89 90 91 |
# File 'lib/navy/orders.rb', line 89 def sailor_mouth @sailor_mouth ||= rank_class::Speak.new(self) end |