Class: VhostWriter::Writer
- Inherits:
-
Object
- Object
- VhostWriter::Writer
- Defined in:
- lib/vhost_writer/writer.rb
Instance Attribute Summary collapse
-
#conf_dir ⇒ Object
readonly
Returns the value of attribute conf_dir.
-
#sites ⇒ Object
readonly
Returns the value of attribute sites.
Instance Method Summary collapse
- #blacklist(site_blacklist) ⇒ Object
-
#initialize(options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #whitelist(site_whitelist) ⇒ Object
- #write_configs!(template) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Writer
Returns a new instance of Writer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vhost_writer/writer.rb', line 7 def initialize(={}) raise ArgumentError, ':conf_dir is required' unless .key? :conf_dir raise ArgumentError, 'Either :sites_dir or :sites is required' unless .key? :sites_dir or .key? :sites raise ArgumentError, 'Only one of :sites_dir and :sites is allowed' if .key? :sites_dir and .key? :sites [:conf_dir] << '/' unless [:conf_dir] =~ /\/\z/ @conf_dir = [:conf_dir] if .key? :sites_dir @sites = Dir.glob("#{[:sites_dir]}*").map { |f| File.basename f } else @sites = [:sites] end end |
Instance Attribute Details
#conf_dir ⇒ Object (readonly)
Returns the value of attribute conf_dir.
5 6 7 |
# File 'lib/vhost_writer/writer.rb', line 5 def conf_dir @conf_dir end |
#sites ⇒ Object (readonly)
Returns the value of attribute sites.
5 6 7 |
# File 'lib/vhost_writer/writer.rb', line 5 def sites @sites end |
Instance Method Details
#blacklist(site_blacklist) ⇒ Object
22 23 24 |
# File 'lib/vhost_writer/writer.rb', line 22 def blacklist(site_blacklist) Writer.new :conf_dir => @conf_dir, :sites => @sites - site_blacklist end |
#whitelist(site_whitelist) ⇒ Object
26 27 28 |
# File 'lib/vhost_writer/writer.rb', line 26 def whitelist(site_whitelist) Writer.new :conf_dir => @conf_dir, :sites => site_whitelist - (@sites - site_whitelist) end |
#write_configs!(template) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/vhost_writer/writer.rb', line 30 def write_configs!(template) @sites.each do |site| File.open("#{@conf_dir}#{site}", 'w') do |f| f.write ERB.new(template).result(binding) end end end |