lib/fig/statement/configuration.rb in fig-0.1.62 vs lib/fig/statement/configuration.rb in fig-0.1.64
- old
+ new
@@ -1,26 +1,29 @@
require 'fig/statement'
require 'fig/statement/command'
module Fig; end
-# A grouping of statements within a configuration. May not be nested.
+# A grouping of statements within a package. May not be nested.
+#
+# Any processing of statements is guaranteed to hit any Overrides first.
class Fig::Statement::Configuration < Fig::Statement
attr_reader :name, :statements
- def initialize(line_column, name, statements)
- super(line_column)
+ def initialize(line_column, source_description, name, statements)
+ super(line_column, source_description)
@name = name
- @statements = statements
- end
- def with_name(name)
- Configuration.new(name, statements)
+ overrides, others = statements.partition do
+ |statement| statement.is_a?(Fig::Statement::Override)
+ end
+
+ @statements = [overrides, others].flatten
end
- def command
+ def command_statement
return statements.find do
|statement| statement.is_a?(Fig::Statement::Command)
end
end
@@ -30,21 +33,18 @@
yield statement
statement.walk_statements &block
end
end
- # Block will receive a Package and a Statement.
- def walk_statements_following_package_dependencies(repository, package, configuration, &block)
- @statements.each do |statement|
- yield package, self, statement
- statement.walk_statements_following_package_dependencies(
- repository, package, self, &block
- )
- end
-
- return
- end
-
def unparse(indent)
unparse_statements(indent, "config #{@name}", @statements, 'end')
+ end
+
+ private
+
+ def unparse_statements(indent, prefix, statements, suffix)
+ body =
+ @statements.map {|statement| statement.unparse(indent + ' ') }.join("\n")
+
+ return ["\n#{indent}#{prefix}", body, "#{indent}#{suffix}"].join("\n")
end
end