Permalink
Browse files

Add component version comparisons to allow developers to override def…

…aults in ~/.rails-up
  • Loading branch information...
Gabriel Evans
Gabriel Evans committed Jan 13, 2012
1 parent 1d15040 commit 23071f08998f21c820cd67d604038424e5b8f087
Showing with 29 additions and 26 deletions.
  1. +1 −1 lib/rails-up/component.rb
  2. +1 −1 lib/rails-up/component_builder.rb
  3. +27 −24 lib/rails-up/components.rb
@@ -52,7 +52,7 @@ def valid?
def validate
raise RailsUp::ComponentDefinitionError, "Name is required" if name.nil? || name.empty?
- raise RailsUp::ComponentDefinitionError, "Version is required" if version.nil? || version.empty?
+ raise RailsUp::ComponentDefinitionError, "Version is required" if version.nil? || version.version.empty?
end
end # Component
@@ -17,7 +17,7 @@ def name(value)
end
def version(value)
- @definition.version = value
+ @definition.version = Gem::Version.new(value)
end
def summary(value)
View
@@ -15,31 +15,34 @@ def mappings
# Attempts to require all components in the load path.
# Awesome snippet repurposed from https://github.com/redcar/plugin_manager
def load_components!
- $LOAD_PATH.each do |base|
- definition_files = Dir[File.join(File.expand_path("#{base}/.."), "components", "{*/component.rb,*_component.rb}")]
- definition_files.each do |file|
- begin
- definition = instance_eval(File.read(file))
-
- definition.definition_file = File.expand_path(file)
-
- if !definition.single_file?
- definition.cookbooks_path = File.expand_path("#{File.dirname(file)}/cookbooks") if File.directory?("#{File.dirname(file)}/cookbooks")
- definition.roles_path = File.expand_path("#{File.dirname(file)}/roles") if File.directory?("#{File.dirname(file)}/roles")
- end
-
- if RailsUp::Components.mappings.has_key?(definition.name)
- # TODO: Detect/differentiate versions of multiple components
- puts "Skipped duplicate component definition: #{file}"
- else
- RailsUp::Components.mappings[definition.name] = definition
- end
- rescue Object => e
- puts "Unreadable component definition: #{file}"
- puts " " + e.message
- puts e.backtrace.map {|l| " " + l}
- nil
+ definition_files = $LOAD_PATH.collect do |base|
+ Dir[File.join(File.expand_path("#{base}/.."), "components", "{*/component.rb,*_component.rb}")]
+ end
+
+ # Search ~/.rails-up for user components
+ definition_files << Dir[File.join(File.expand_path("#{ENV['HOME']}"), ".rails-up", "components", "{*/component.rb,*_component.rb}")]
+
+ definition_files.flatten.each do |file|
+ begin
+ definition = instance_eval(File.read(file))
+
+ definition.definition_file = File.expand_path(file)
+
+ if !definition.single_file?
+ definition.cookbooks_path = File.expand_path("#{File.dirname(file)}/cookbooks") if File.directory?("#{File.dirname(file)}/cookbooks")
+ definition.roles_path = File.expand_path("#{File.dirname(file)}/roles") if File.directory?("#{File.dirname(file)}/roles")
+ end
+
+ if self.mappings.has_key?(definition.name) && self.mappings[definition.name].version >= definition.version
+ puts "Skipped duplicate component definition: #{file}"
+ else
+ self.mappings[definition.name] = definition
end
+ rescue Object => e
+ puts "Unreadable component definition: #{file}"
+ puts " " + e.message
+ puts e.backtrace.map {|l| " " + l}
+ nil
end
end
end

0 comments on commit 23071f0

Please sign in to comment.