Class: Capistrano::Campout::Options

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/capistrano-campout/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



35
36
37
# File 'lib/capistrano-campout/options.rb', line 35

def defaults
  @defaults
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/capistrano-campout/options.rb', line 64

def empty?
  marshal_dump.empty?
end

#filesObject



57
58
59
60
61
62
# File 'lib/capistrano-campout/options.rb', line 57

def files
  if(@files.nil? or @files.empty?)
    @files = ["#{File.join(File.dirname(__FILE__), "defaults.yml").to_s}","./config/campout.yml","./config/campout.local.yml"]
  end
  @files
end

#files=(*files) ⇒ Object



51
52
53
54
55
# File 'lib/capistrano-campout/options.rb', line 51

def files=(*files)
  if(!files.empty?)
    @files = [files].flatten.compact.uniq
  end
end

#load_from_files(*files) ⇒ Object



68
69
70
71
# File 'lib/capistrano-campout/options.rb', line 68

def load_from_files(*files)
  self.files=files
  self.load!
end

#merge!(hash) ⇒ Object



121
122
123
124
125
126
# File 'lib/capistrano-campout/options.rb', line 121

def merge!(hash)
  current = to_hash
  DeepMerge.deep_merge!(current, hash.dup)
  marshal_load(__convert(hash).marshal_dump)
  self
end

#reload!Object Also known as: load!

look through all our sources and rebuild the configuration



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/capistrano-campout/options.rb', line 87

def reload!
  self.reset_sources!
  conf = {}
  @config_sources.each do |source|
    source_conf = source.load

    if conf.empty?
      conf = source_conf
    else
      DeepMerge.deep_merge!(source_conf, conf, :preserve_unmergeables => false)
    end
  end

  # swap out the contents of the OStruct with a hash (need to recursively convert)
  marshal_load(__convert(conf).marshal_dump)

  return self
end

#reload_from_files(*files) ⇒ Object



73
74
75
76
# File 'lib/capistrano-campout/options.rb', line 73

def reload_from_files(*files)
  self.files=files
  self.reload!
end

#reset_sources!Object



78
79
80
81
82
83
84
# File 'lib/capistrano-campout/options.rb', line 78

def reset_sources!
  self.files.each do |file|
    source = (Sources::YAMLSource.new(file)) if file.is_a?(String)          
    @config_sources ||= []
    @config_sources << source
  end
end

#to_hashObject



108
109
110
111
112
113
114
# File 'lib/capistrano-campout/options.rb', line 108

def to_hash
  result = {}
  marshal_dump.each do |k, v|
    result[k] = v.instance_of?(RailsConfig::Options) ? v.to_hash : v
  end
  result
end

#to_json(*args) ⇒ Object



116
117
118
119
# File 'lib/capistrano-campout/options.rb', line 116

def to_json(*args)
  require "json" unless defined?(JSON)
  to_hash.to_json(*args)
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/capistrano-campout/options.rb', line 37

def valid?
  # requires the following settings
  # campfire:
  #   domain:
  #   token:
  #   room:
  
  return false if(self.campfire.nil?)
  return false if(self.campfire.domain.nil?)
  return false if(self.campfire.token.nil?)
  return false if(self.campfire.room.nil?)
  return true
end