lib/xcake/configurable.rb in xcake-0.6.10 vs lib/xcake/configurable.rb in xcake-0.6.11
- old
+ new
@@ -13,99 +13,113 @@
#
module Configurable
private
- attr_accessor :all_configurations
+ attr_accessor :configurations
public
- attr_accessor :debug_configurations
- attr_accessor :release_configurations
-
- # @return [Array<Configuration>] list of configurations
+ # @return [Array<Configuration>] list of all configurations
#
def all_configurations
- configurations = []
+ if @configurations.nil?
+ @configurations = []
- if debug_configurations.empty?
- configurations << debug_configuration("Debug")
- else
- configurations.concat(debug_configurations)
+ parent_configurable.all_configurations.each do |c|
+ configuration(c.name, c.type)
+ end if parent_configurable
end
- if release_configurations.empty?
- configurations << release_configuration("Release")
- else
- configurations.concat(release_configurations)
- end
-
- configurations
+ @configurations
end
- # @return [Array<Configuration>] list of debug configurations
+ # @param [Array<Configuration>] new list of configurations to set
#
- def debug_configurations
- @debug_configurations ||= []
+ def all_configurations=(configurations)
+ @configurations = configurations
end
- # @return [Array<Configuration>] list of release configurations
+ # @return [Array<Configuration>] list of configurations of a type
#
- def release_configurations
- @release_configurations ||= []
+ def configurations_of_type(type)
+ all_configurations.select do |c|
+ c.type == type
+ end
end
# This either finds a release configuration
# with the same name or creates one.
#
+ # @deprecated Please use `configuration <name>, :debug` this
+ # woll be removed in 0.7.0
+ #
# @return [Configuration] the new or existing debug configuration
#
def debug_configuration(name = nil, &block)
- build_configuration(:debug, name, &block)
+ configuration(name, :debug, &block)
end
# This either finds a release configuration
# with the same name or creates one.
#
+ # @deprecated Please use `configuration <name>, :release` this
+ # woll be removed in 0.7.0
+ #
# @return [Configuration] the new or existing release configuration
#
def release_configuration(name = nil, &block)
- build_configuration(:release, name, &block)
+ configuration(name, :release, &block)
end
- private
+ # This either finds a configuration
+ # with the same name and type or creates one.
+ #
+ # @return [Configuration] the new or existing configuration
+ #
+ def configuration(name, type, &block)
- def build_configuration(method, name, &block)
- case method
- when :debug
- configuration_name = debug_configurations
- default_settings = default_debug_settings
- when :release
- configuration_name = release_configurations
- default_settings = default_release_settings
- end
+ default_settings = default_settings_for_type(type)
+ configurations = configurations_of_type(type)
if name.nil?
- build_configuration = configuration_name.first
+ build_configuration = configurations.first
else
- build_configuration = configuration_name.detect do |c|
+ build_configuration = configurations.detect do |c|
c.name == name.to_s
end
end
if build_configuration.nil?
- if name.nil?
- name = method.to_s[0].upcase + method.to_s[1..-1]
- end
+ name = type.to_s.capitalize if name.nil?
+
build_configuration = Configuration.new(name) do |b|
+
+ b.type = type
b.settings.merge!(default_settings)
+
block.call(b) if block_given?
end
- configuration_name << build_configuration
+ all_configurations << build_configuration
end
build_configuration
+ end
+
+ private
+
+ def parent_configurable
+ nil
+ end
+
+ def default_settings_for_type(type)
+ case type
+ when :debug
+ default_debug_settings
+ when :release
+ default_release_settings
+ end
end
end
end