You are viewing a plain text version of this content. The canonical link for it is here.
Posted to alois-commits@incubator.apache.org by fl...@apache.org on 2010/11/04 18:27:42 UTC
svn commit: r1031127 [22/22] - in /incubator/alois/trunk: ./ bin/ debian/
doc/ etc/ etc/alois/ etc/alois/apache2/ etc/alois/environments/
etc/alois/prisma/ etc/cron.d/ etc/default/ etc/logrotate.d/ prisma/
prisma/bin/ prisma/conf/ prisma/conf/prisma/ p...
Added: incubator/alois/trunk/rails_plugins/gemsonrails/init.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails_plugins/gemsonrails/init.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails_plugins/gemsonrails/init.rb (added)
+++ incubator/alois/trunk/rails_plugins/gemsonrails/init.rb Thu Nov 4 18:27:22 2010
@@ -0,0 +1,14 @@
+gems = Dir[File.join(RAILS_ROOT, "vendor/gems/*")]
+if gems.any?
+ # Prepend load paths first so that gems can depend on eachother
+ gems.each do |dir|
+ lib = File.join(dir, 'lib')
+ $LOAD_PATH.unshift(lib) if File.directory?(lib)
+ end
+
+ # Require each gem
+ gems.each do |dir|
+ init_rb = File.join(dir, 'init.rb')
+ require init_rb if File.file?(init_rb)
+ end
+end
\ No newline at end of file
Added: incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_freeze.rake
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_freeze.rake?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_freeze.rake (added)
+++ incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_freeze.rake Thu Nov 4 18:27:22 2010
@@ -0,0 +1,91 @@
+namespace :gems do
+ desc "Freeze a RubyGem into this Rails application; init.rb will be loaded on startup."
+ task :freeze do
+ unless gem_name = ENV['GEM']
+ puts <<-eos
+Parameters:
+ GEM Name of gem (required)
+ VERSION Version of gem to freeze (optional)
+ ONLY RAILS_ENVs for which the GEM will be active (optional)
+
+eos
+ break
+ end
+
+ # ONLY=development[,test] etc
+ only_list = (ENV['ONLY'] || "").split(',')
+ only_if_begin = only_list.size == 0 ? "" : <<-EOS
+ENV['RAILS_ENV'] ||= 'development'
+if %w[#{only_list.join(' ')}].include?(ENV['RAILS_ENV'])
+ EOS
+ only_if_end = only_list.size == 0 ? "" : "end"
+ only_if_tab = only_list.size == 0 ? "" : " "
+
+ require 'rubygems'
+ # RubyGems <0.9.5
+ # Gem.manage_gems
+ # Gem::CommandManager.new
+
+ # RubyGems >=0.9.5
+ require 'rubygems/command_manager'
+ require 'rubygems/commands/unpack_command'
+ Gem::CommandManager.instance
+
+ gem = (version = ENV['VERSION']) ?
+ Gem.cache.search(gem_name, "= #{version}").first :
+ Gem.cache.search(gem_name).sort_by { |g| g.version }.last
+
+ version ||= gem.version.version rescue nil
+
+ unpack_command_class = Gem::UnpackCommand rescue nil || Gem::Commands::UnpackCommand
+ unless gem && path = unpack_command_class.new.get_path(gem_name, version)
+ raise "No gem #{gem_name} #{version} is installed. Do 'gem list #{gem_name}' to see what you have available."
+ end
+
+ gems_dir = File.join(RAILS_ROOT, 'vendor', 'gems')
+ mkdir_p gems_dir, :verbose => false if !File.exists?(gems_dir)
+
+ target_dir = ENV['TO'] || File.basename(path).sub(/\.gem$/, '')
+ mkdir_p "vendor/gems/#{target_dir}", :verbose => false
+
+ chdir gems_dir, :verbose => false do
+ mkdir_p target_dir, :verbose => false
+ abs_target_dir = File.join(Dir.pwd, target_dir)
+
+ (gem = Gem::Installer.new(path)).unpack(abs_target_dir)
+ chdir target_dir, :verbose => false do
+ if !File.exists?('init.rb')
+ File.open('init.rb', 'w') do |file|
+ path_options = [gem_name, gem_name.split('-').join('/')].map {|n|
+# TODO: this is not nice
+if n == "InlineAttachment" then "inline_attachment" else
+ if n == "acts_as_reportable" then "ruport/acts_as_reportable" else n end
+end
+}.uniq
+ code = <<-eos
+require_options = #{path_options.inspect}
+if require_lib = require_options.find { |path|
+ File.exist?(File.join(File.dirname(__FILE__), 'lib', path + '.rb')) or
+ File.directory?(File.join(File.dirname(__FILE__), 'lib', path))
+ }
+ require File.join(File.dirname(__FILE__), 'lib', require_lib)
+else
+ puts msg = "ERROR: Please update \#{File.expand_path __FILE__} with the require path for linked RubyGem #{gem_name}"
+ exit
+end
+ eos
+ tabbed_code = code.split("\n").map { |line| line = "#{only_if_tab}#{line}" }.join("\n")
+
+ file << <<-eos
+#{only_if_begin}
+#{tabbed_code}
+#{only_if_end}
+ eos
+ end
+ end
+ end
+ puts "Unpacked #{gem_name} #{version} to '#{target_dir}'"
+ end
+ end
+
+end
Added: incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_link.rake
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_link.rake?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_link.rake (added)
+++ incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_link.rake Thu Nov 4 18:27:22 2010
@@ -0,0 +1,102 @@
+namespace :gems do
+ desc "Link a RubyGem into this Rails application; init.rb will be loaded on startup."
+ task :link do
+ unless gem_name = ENV['GEM']
+ puts <<-eos
+Parameters:
+ GEM Name of gem (required)
+ ONLY RAILS_ENVs for which the GEM will be active (optional)
+
+eos
+ break
+ end
+
+ # ONLY=development[,test] etc
+ only_list = (ENV['ONLY'] || "").split(',')
+ only_if_begin = only_list.size == 0 ? "" : <<-EOS
+ENV['RAILS_ENV'] ||= 'development'
+if %w[#{only_list.join(' ')}].include?(ENV['RAILS_ENV'])
+ EOS
+ only_if_end = only_list.size == 0 ? "" : "end"
+ only_if_tab = only_list.size == 0 ? "" : " "
+
+ require 'rubygems'
+ # RubyGems <0.9.5
+ # Gem.manage_gems
+ # Gem::CommandManager.new
+
+ # RubyGems >=0.9.5
+ require 'rubygems/command_manager'
+ require 'rubygems/commands/unpack_command'
+ Gem::CommandManager.instance
+
+ gem = Gem.cache.search(gem_name).sort_by { |g| g.version }.last
+ version ||= gem.version.version rescue nil
+
+ unpack_command_class = Gem::UnpackCommand rescue nil || Gem::Commands::UnpackCommand
+ unless gem && path = unpack_command_class.new.get_path(gem_name, version)
+ raise "No gem #{gem_name} is installed. Try 'gem install #{gem_name}' to install the gem."
+ end
+
+ gems_dir = File.join(RAILS_ROOT, 'vendor', 'gems')
+ mkdir_p gems_dir, :verbose => false if !File.exists?(gems_dir)
+
+ target_dir = ENV['TO'] || gem.name
+ mkdir_p "vendor/gems/#{target_dir}"
+
+ chdir gems_dir, :verbose => false do
+ mkdir_p target_dir + '/tasks', :verbose => false
+ chdir target_dir, :verbose => false do
+ File.open('init.rb', 'w') do |file|
+ path_options = [gem_name, gem_name.split('-').join('/')].uniq
+ code = <<-eos
+require 'rubygems'
+Gem.manage_gems
+gem = Gem.cache.search('#{gem.name}').sort_by { |g| g.version }.last
+if gem.autorequire
+ require gem.autorequire
+else
+ require_options = #{path_options.inspect}
+ unless require_options.find do |path|
+ begin
+ require path
+ rescue MissingSourceFile
+ nil
+ end
+ end
+ puts msg = "ERROR: Please update \#{File.expand_path __FILE__} with the require path for linked RubyGem #{gem_name}"
+ exit
+ end
+end
+ eos
+ tabbed_code = code.split("\n").map { |line| line = "#{only_if_tab}#{line}" }.join("\n")
+ file << <<-eos
+#{only_if_begin}
+#{tabbed_code}
+#{only_if_end}
+eos
+ end
+ File.open(File.join('tasks', 'load_tasks.rake'), 'w') do |file|
+ file << <<-eos
+# This file does not include any Rake files, but loads up the
+# tasks in the /vendor/gems/ folders
+#{only_if_begin}
+ require 'rubygems'
+ Gem.manage_gems
+ gem = Gem.cache.search('#{gem.name}').sort_by { |g| g.version }.last
+ raise \"Gem '#{gem.name}' is not installed\" if gem.nil?
+ path = gem.full_gem_path
+ Dir[File.join(path, "/**/tasks/**/*.rake")].sort.each { |ext| load ext }
+#{only_if_end}
+eos
+ end
+ puts "Linked #{gem_name} (currently #{version}) via 'vendor/gems/#{target_dir}'"
+ end
+ end
+ end
+
+ task :unfreeze do
+ raise "No gem specified" unless gem_name = ENV['GEM']
+ Dir["vendor/gems/#{gem_name}-*"].each { |d| rm_rf d }
+ end
+end
\ No newline at end of file
Added: incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_unfreeze.rake
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_unfreeze.rake?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_unfreeze.rake (added)
+++ incubator/alois/trunk/rails_plugins/gemsonrails/tasks/gems_unfreeze.rake Thu Nov 4 18:27:22 2010
@@ -0,0 +1,15 @@
+namespace :gems do
+ desc "Unfreeze/unlink a RubyGem from this Rails application"
+ task :unfreeze do
+ unless gem_name = ENV['GEM']
+ puts <<-eos
+Parameters:
+ GEM Name of gem (required)
+
+
+eos
+ break
+ end
+ Dir["vendor/gems/#{gem_name}*"].each { |d| rm_rf d }
+ end
+end
\ No newline at end of file
Added: incubator/alois/trunk/rails_plugins/gemsonrails/tasks/load_tasks_in_gems.rake
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails_plugins/gemsonrails/tasks/load_tasks_in_gems.rake?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails_plugins/gemsonrails/tasks/load_tasks_in_gems.rake (added)
+++ incubator/alois/trunk/rails_plugins/gemsonrails/tasks/load_tasks_in_gems.rake Thu Nov 4 18:27:22 2010
@@ -0,0 +1,10 @@
+# This file does not include any Rake files, but loads up the
+# tasks in the /vendor/gems/ folders
+
+Dir[File.join(RAILS_ROOT, "vendor/gems/*/**/tasks/**/*.rake")].sort.each do |ext|
+ begin
+ load ext
+ rescue
+ puts $!
+ end
+end
\ No newline at end of file
Added: incubator/alois/trunk/usr/lib/ruby/1.8/acts_as_reportable.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/usr/lib/ruby/1.8/acts_as_reportable.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/usr/lib/ruby/1.8/acts_as_reportable.rb (added)
+++ incubator/alois/trunk/usr/lib/ruby/1.8/acts_as_reportable.rb Thu Nov 4 18:27:22 2010
@@ -0,0 +1,172 @@
+# Copyright 2010 The Apache Software Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module Ruport
+
+ # This module is designed to be mixed in with an ActiveRecord model
+ # to add easy conversion to Ruport's data structures.
+ module Reportable
+
+ def self.included(base) # :nodoc:
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+
+ # In the ActiveRecord model you wish to integrate with Ruport, add the
+ # following line just below the class definition:
+ #
+ # acts_as_reportable
+ #
+ # This will automatically make all the methods in this module available
+ # in the model.
+ def acts_as_reportable
+ include Ruport::Reportable::InstanceMethods
+ extend Ruport::Reportable::SingletonMethods
+ end
+ end
+
+ module SingletonMethods
+ # Creates a Ruport::Data::Table from an ActiveRecord find. Takes
+ # parameters just like a regular Active find. If you use the :include
+ # option, it will return a table with all columns from the model and
+ # the included associations. If you use the :columns option, it will
+ # return a table with only the specified columns. To access a column
+ # in an associated table, use the association in the column name.
+ #
+ # Example:
+ #
+ # class Book < ActiveRecord::Base
+ # belongs_to :author
+ # acts_as_reportable
+ # end
+ #
+ # Book.report_table(:all, :columns => ['title', 'author.name']).as(:html)
+ #
+ # Returns: a html version of a report with two columns, title from
+ # the book, and name from the associated author.
+ #
+
+ # Calling Book.report_table(:all, :include => [:author]).as(:html) will
+ # return a table with all columns from books and authors.
+ #
+ def report_table(number = :all, options = {})
+
+ options[:include] ||= []
+ report_columns = options.delete(:columns)
+ report_columns ||= column_names + options[:include].map {|x| reflect_on_association(x).klass.column_names.map {|y| "#{x}.#{y}"}}.flatten
+
+ includes, attributes = split_columns report_columns
+
+ options[:include] = (options[:include] + includes).uniq
+
+ data = find(number,options).map do |r|
+ r.get_attributes_with_associations :only => attributes,
+ :include => options[:include]
+ end
+
+ Ruport::Data::Table.new(:data => data,
+ :column_names => report_columns).reorder(report_columns)
+ end
+
+
+ private
+
+ # Split an array of columns into associations and attributes.
+ #
+ # Example: split_columns(['title','author.name'])
+ # Returns: [:author], ['title','name']
+ #
+ def split_columns(columns)
+ includes = []
+ attributes = []
+
+ columns.each do |column|
+ include,attribute = column.split(/\./)
+
+ attributes << (attribute || include)
+ includes << include.to_sym if attribute
+ end if columns
+
+ return includes, attributes
+ end
+
+ end
+
+ module InstanceMethods
+ # Instance methods for ActiveRecord objects. Grabs all of the
+ # object's attributes and the attributes of the associated objects
+ # and returns them in a hash. Associated object attributes are
+ # stored in the hash with "association.attribute" keys. Passing
+ # :only as an option will only get those attributes. Must pass
+ # :include as an option to access associations.
+ #
+ # Example:
+ #
+ # class Book < ActiveRecord::Base
+ # belongs_to :author
+ # acts_as_reportable
+ # end
+ #
+ # abook.get_attributes_with_associations(:only => ['title','name'],
+ # :include => [:author])
+ # returns: {'title' => 'books title',
+ # 'author.name' => 'authors name',
+ # 'author.title' => 'Mr.',
+ # 'name' => 'book name' }
+ #
+ # NOTE: author.title and name will only be returned if those values
+ # exist in the tables. If the books table does not have a name column,
+ # name will not be returned. Likewise, if the authors table does not
+ # have a title column, it will not be returned.
+ #
+ def get_attributes_with_associations(options = {})
+ options[:root] ||= self.class.to_s.underscore
+ root_only_or_except =
+ if options[:only] or options[:except]
+ { :only => options[:only], :except => options[:except] }
+ else
+ nil
+ end
+ attrs = attributes(root_only_or_except)
+
+ if include_associations = options.delete(:include)
+ include_has_options = include_associations.is_a?(Hash)
+
+ for association in include_has_options ? include_associations.keys : Array(include_associations)
+ association_options = include_has_options ? include_associations[association] : root_only_or_except
+
+ case self.class.reflect_on_association(association).macro
+
+ when :has_many, :has_and_belongs_to_many
+ #records = send(association).to_a
+ #unless records.empty?
+ # attrs[association] = records.collect do |record|
+ # record.attributes(association_options)
+ # end
+ #end
+
+ when :has_one, :belongs_to
+ if record = send(association)
+ attrs = record.attributes().inject(attrs) {|h,(k,v)| h["#{association}.#{k}"] = v; h }
+ end
+ end
+ end
+ end
+
+ attrs
+ end
+ end
+ end
+end
\ No newline at end of file