Class: Navy::Orders

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/orders.rb

Direct Known Subclasses

Admiral::Orders, Captain::Orders

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @rank_class = rank_class
  self.set = Hash.new(:unset)
  self.config_file = options.delete(:config_file)
  @use_defaults = options.delete(:use_defaults)

  set.merge!(defaults) if @use_defaults
  options.each { |key, value| sailor_mouth.__send__(key, value) }

  reload(false)
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



40
41
42
# File 'lib/navy/orders.rb', line 40

def config_file
  @config_file
end

#defaultsObject



20
21
22
# File 'lib/navy/orders.rb', line 20

def defaults
  defined?(@defaults) ? @defaults : self.class.defaults
end

#rank_classObject (readonly)

Returns the value of attribute rank_class.



39
40
41
# File 'lib/navy/orders.rb', line 39

def rank_class
  @rank_class
end

#setObject

Returns the value of attribute set.



40
41
42
# File 'lib/navy/orders.rb', line 40

def set
  @set
end

Class Method Details

.defaultsObject

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

Returns:

  • (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

Returns:

  • (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, options = {})
  only   = options[:only]   || []
  except = options[: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_mouthObject



89
90
91
# File 'lib/navy/orders.rb', line 89

def sailor_mouth
  @sailor_mouth ||= rank_class::Speak.new(self)
end