Class: WordpressDeploy::Environment
- Inherits:
-
Object
- Object
- WordpressDeploy::Environment
- Defined in:
- lib/wordpress_deploy/environment.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#base_url(new_base = nil) ⇒ Object
This is the url to search the the database for.
- #database(&block) ⇒ Object
-
#initialize(name, store = true, &block) ⇒ Environment
constructor
A new instance of Environment.
- #salts(&block) ⇒ Object
-
#save_wp_config ⇒ Object
Write the file the filesystem.
- #transfer(type = nil, &block) ⇒ Object
- #wpdebug(new_wp_debug = nil) ⇒ Object
- #wplang(new_wp_lang = nil) ⇒ Object
Constructor Details
#initialize(name, store = true, &block) ⇒ Environment
Returns a new instance of Environment.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wordpress_deploy/environment.rb', line 6 def initialize(name, store = true, &block) @name = name @base_url ||= "localhost" @wplang ||= "" @wpdebug ||= false # Get an Erb template @template = ERB.new(File.read(File.join(WordpressDeploy::TEMPLATE_PATH, "wp-config.erb"))) @output = Environment.output_file instance_eval(&block) if block_given? Environments << self if store end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/wordpress_deploy/environment.rb', line 4 def name @name end |
Instance Method Details
#base_url(new_base = nil) ⇒ Object
This is the url to search the the database for.
23 24 25 26 |
# File 'lib/wordpress_deploy/environment.rb', line 23 def base_url(new_base = nil) @base_url = new_base.to_s unless new_base.nil? @base_url end |
#database(&block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/wordpress_deploy/environment.rb', line 30 def database(&block) @database ||= WordpressDeploy::Database::MySql.new @database.instance_eval(&block) if block_given? @database.base_url base_url @database end |
#salts(&block) ⇒ Object
39 40 41 42 43 |
# File 'lib/wordpress_deploy/environment.rb', line 39 def salts(&block) @salts ||= WordpressDeploy::Wordpress::Salts.new @salts.instance_eval(&block) if block_given? @salts end |
#save_wp_config ⇒ Object
Write the file the filesystem
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wordpress_deploy/environment.rb', line 58 def save_wp_config # Remove the output file if is already there FileUtils.rm @output if File.exists? @output # Open the output file File.open(@output, 'w') do |f| # Evaluate the ERB template f.write @template.result(get_binding) end end |
#transfer(type = nil, &block) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/wordpress_deploy/environment.rb', line 47 def transfer(type = nil, &block) unless type.nil? klass = get_class_from_scope(WordpressDeploy::Storage, type) @transfer ||= klass.new @transfer.instance_eval(&block) if block_given? end @transfer end |
#wpdebug(new_wp_debug = nil) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/wordpress_deploy/environment.rb', line 78 def wpdebug(new_wp_debug = nil) # Only assign if argument is a boolean value # http://stackoverflow.com/questions/3028243/check-if-ruby-object-is-a-boolean @wpdebug = new_wp_debug if (new_wp_debug.is_a?(TrueClass) || new_wp_debug.is_a?(FalseClass)) @wpdebug.to_s end |
#wplang(new_wp_lang = nil) ⇒ Object
71 72 73 74 |
# File 'lib/wordpress_deploy/environment.rb', line 71 def wplang(new_wp_lang = nil) @wplang = new_wp_lang.to_s unless new_wp_lang.nil? @wplang end |