merb-freezer 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Matt Aimonetti
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ merb-freezer
2
+ ============
3
+
4
+ see README.markdown
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ PLUGIN = "merb-freezer"
5
+ NAME = "merb-freezer"
6
+ VERSION = "0.9.3"
7
+ AUTHOR = "Matt Aimonetti"
8
+ EMAIL = "mattaimonetti@gmail.com"
9
+ HOMEPAGE = "http://www.merbivore.com"
10
+ SUMMARY = "Merb plugin that let's you freeze Merb"
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = NAME
14
+ s.version = VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+ s.require_path = 'lib'
24
+ s.bindir = "bin"
25
+ s.executables = %w( frozen-merb )
26
+ s.autorequire = PLUGIN
27
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
28
+ end
29
+
30
+ Rake::GemPackageTask.new(spec) do |pkg|
31
+ pkg.gem_spec = spec
32
+ end
33
+
34
+ desc "install merb-freezer"
35
+ task :install => [:package] do
36
+ sh %{sudo gem install pkg/#{NAME}-#{VERSION} --no-update-sources}
37
+ end
38
+
39
+ namespace :jruby do
40
+
41
+ desc "Run :package and install the resulting .gem with jruby"
42
+ task :install => :package do
43
+ sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
44
+ end
45
+
46
+ end
data/TODO ADDED
File without changes
data/bin/frozen-merb ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = nil
4
+ %w[-m --merb-root].detect { |o| root = ARGV.index(o) }
5
+ __DIR__ = root ? ARGV[root+1] : Dir.getwd
6
+ framework = File.join(__DIR__,"framework")
7
+
8
+ # load merb from the framework folder
9
+ if File.directory?(framework)
10
+ puts "Running from frozen framework"
11
+ core = File.join(framework,"merb-core")
12
+ if File.directory?(core)
13
+ puts "using merb-core from #{core}"
14
+ $:.unshift File.join(core,"lib")
15
+ end
16
+ more = File.join(framework,"merb-more")
17
+ if File.directory?(more)
18
+ Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
19
+ $:.unshift File.join(more,d,'lib')
20
+ end
21
+ end
22
+ plugins = File.join(framework,"merb-plugins")
23
+ if File.directory?(plugins)
24
+ Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
25
+ $:.unshift File.join(plugins,d,'lib')
26
+ end
27
+ end
28
+ require "merb-core/core_ext/kernel"
29
+ require "merb-core/core_ext/rubygems"
30
+ else
31
+ # load from the gems folder
32
+ gem = Dir["./gems/gems/merb-core-*"].last
33
+ if gem
34
+ require gem + "/lib/merb-core/core_ext/kernel"
35
+ require gem + "/lib/merb-core/core_ext/rubygems"
36
+
37
+ Gem.clear_paths
38
+ Gem.path.unshift(__DIR__+"/gems")
39
+ else
40
+ puts "Can't run frozen Merb from framework/ and/or gems/ please freeze Merb"
41
+ puts "Merb will try to start using the system gems"
42
+ end
43
+ end
44
+
45
+ # load submodule gems
46
+ gem_submodules_dir = File.join(__DIR__,"gems/submodules")
47
+ if File.directory?(gem_submodules_dir)
48
+ Dir["#{gem_submodules_dir}/*"].each do |dir|
49
+ $:.unshift File.join(dir,"lib")
50
+ end
51
+ end
52
+
53
+ require 'merb-core'
54
+ unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
55
+ ARGV.push *%w[-a mongrel]
56
+ end
57
+
58
+ Merb.frozen! if (File.directory?(framework) || gem)
59
+ Merb.start
@@ -0,0 +1,21 @@
1
+ require 'merb-freezer/freezer'
2
+ require 'fileutils'
3
+
4
+ # make sure we're running inside Merb
5
+ if defined?(Merb::Plugins)
6
+
7
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
8
+ Merb::Plugins.config[:merb_freezer] = {
9
+ :merb_best_framework_ever => true
10
+ }
11
+
12
+ Merb::BootLoader.before_app_loads do
13
+ # require code that must be loaded before the application
14
+ end
15
+
16
+ Merb::BootLoader.after_app_loads do
17
+ # code that can be required after the application loads
18
+ end
19
+
20
+ Merb::Plugins.add_rakefiles "merb-freezer/merbtasks"
21
+ end
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/freezer_mode'
2
+
3
+ class Freezer
4
+ include FreezerMode
5
+
6
+ attr_reader :mode, :component, :update
7
+ attr_accessor :freezer_dir
8
+
9
+ @@components =
10
+ {
11
+ "core" => "git://github.com/wycats/merb-core.git",
12
+ "more" => "git://github.com/wycats/merb-more.git",
13
+ "plugins" => "git://github.com/wycats/merb-plugins.git"
14
+ }
15
+
16
+ @@framework_dir = File.join(Dir.pwd, "framework")
17
+ @@gems_dir = File.join(Dir.pwd, "gems")
18
+
19
+ # Returns the components to freeze
20
+ # a class variable is used so we could decide to add a setter and support custom components
21
+ def self.components
22
+ @@components
23
+ end
24
+
25
+ def self.framework_dir
26
+ @@framework_dir
27
+ end
28
+
29
+ def self.gems_dir
30
+ @@gems_dir
31
+ end
32
+
33
+ # Freezes a component
34
+ #
35
+ # ==== Parameters
36
+ # component<String>::
37
+ # The component to freeze, it needs to be defined in @@components
38
+ # update<Boolean>:: An optional value to tell the freezer to update the previously frozen or not, this will default to false
39
+ # mode<String>:: An optional value to tell the freezer what freezer mode to use (submodules or rubygems), this will default to submodules
40
+ #
41
+ def self.freeze(component, update, mode)
42
+ new(component, update, mode).freeze
43
+ end
44
+
45
+ # Initializes a Freeze instance
46
+ #
47
+ # ==== Parameters
48
+ # component<String>::
49
+ # The component to freeze, it needs to be defined in @@components
50
+ # update<Boolean>:: An optional value to tell the freezer to update the previously frozen or not, this will default to false
51
+ # mode<String>:: An optional value to tell the freezer what freezer mode to use (submodules or rubygems), this will default to submodules
52
+ #
53
+ def initialize(component, update=false, mode=nil)
54
+ @component = Freezer.components.keys.include?(component) ? "merb-" + component : component
55
+ @update = update
56
+ if (mode.nil? && framework_component?) || component.match(/^git:\/\//) || mode == 'submodules'
57
+ @mode = 'submodules'
58
+ else
59
+ @mode = 'rubygems'
60
+ end
61
+ @freezer_dir = framework_component? ? Freezer.framework_dir : Freezer.gems_dir
62
+ end
63
+
64
+ # Calls the freezer mode on the component
65
+ def freeze
66
+ puts "Ice, Ice Baby!"
67
+ puts "freezing mode: #{@mode}"
68
+ send "#{@mode}_freeze"
69
+ end
70
+
71
+ # Returns true if the gem is part of the Merb components
72
+ def framework_component?
73
+ Freezer.components.keys.include?(@component.gsub("merb-", ""))
74
+ end
75
+
76
+ end
@@ -0,0 +1,85 @@
1
+ require 'find'
2
+ module FreezerMode
3
+
4
+ def sudo
5
+ windows = (PLATFORM =~ /win32|cygwin/) rescue nil
6
+ sudo = windows ? "" : "sudo"
7
+ end
8
+
9
+ def gitmodules
10
+ File.join(Dir.pwd, ".gitmodules")
11
+ end
12
+
13
+ # Uses the Git submodules to freeze a component
14
+ #
15
+ def submodules_freeze
16
+ # Ensure that required git commands are available
17
+ %w(git-pull git-submodule).each do |bin|
18
+ next if in_path?(bin)
19
+ $stderr.puts "ERROR: #{bin} must be avaible in PATH - you might want to freeze using MODE=rubygems"
20
+ exit 1
21
+ end
22
+
23
+ # Create directory to receive the frozen components
24
+ create_freezer_dir(freezer_dir)
25
+
26
+ if managed?(@component)
27
+ puts "#{@component} seems to be already managed by git-submodule."
28
+ if @update
29
+ puts "Trying to update #{@component} ..."
30
+ `cd #{freezer_dir}/#{@component} && git-pull`
31
+ else
32
+ puts "you might want to call this rake task using UPDATE=true if you wish to update the frozen gems using this task"
33
+ end
34
+ else
35
+ puts "Creating submodule for #{@component} ..."
36
+ if framework_component?
37
+ `cd #{Dir.pwd} & git-submodule --quiet add #{Freezer.components[@component.gsub("merb-", '')]} #{File.basename(freezer_dir)}/#{@component}`
38
+ else
39
+ `cd #{Dir.pwd} & git-submodule --quiet add #{@component} gems/submodules/#{@component.match(/.*\/(.*)\..{3}$/)[1]}`
40
+ end
41
+ if $?.success?
42
+ `git-submodule init`
43
+ else
44
+ # Should this instead be a raise?
45
+ $stderr.puts("ERROR: unable to create submodule for #{@component} - you might want to freeze using MODE=rubygems")
46
+ end
47
+ end
48
+ end
49
+
50
+ # Uses rubygems to freeze the components locally
51
+ #
52
+ def rubygems_freeze
53
+ create_freezer_dir(freezer_dir)
54
+ action = update ? 'update' : 'install'
55
+ puts "#{action} #{@component} and dependencies from rubygems"
56
+ `#{sudo} gem #{action} #{@component} --no-rdoc --no-ri -i #{framework_component? ? 'framework' : 'gems'}`
57
+ end
58
+
59
+ def create_freezer_dir(path)
60
+ unless File.directory?(path)
61
+ puts "Creating freezer directory ..."
62
+ FileUtils.mkdir_p(path)
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ # returns true if submodules are used
69
+ def in_submodule?(component)
70
+ return false unless File.exists?(gitmodules)
71
+ # File.read(gitmodules) =~ %r![submodule "#{freezer_dir}/#{component}"]!
72
+ File.read(gitmodules).match(%r!#{freezer_dir}/#{component}!)
73
+ end
74
+
75
+ # returns true if the component is in a submodule
76
+ def managed?(component)
77
+ File.directory?(File.join(freezer_dir, component)) || in_submodule?(component)
78
+ end
79
+
80
+ def in_path?(bin)
81
+ `which #{bin}`
82
+ !$?.nil? && $?.success?
83
+ end
84
+
85
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/../merb-freezer"
2
+
3
+ task :freeze => Freezer.components.keys.map { |component| "freeze:#{component}" }
4
+ namespace :freeze do
5
+ Freezer.components.each do |component, git_repository|
6
+ desc "Freeze merb-#{component} from #{git_repository} or rubygems - use UPDATE=true to update a frozen component. By default this task uses git submodules. To freeze the latest gems versions use MODE=rubygems"
7
+ task component do
8
+ Freezer.freeze(component, ENV["UPDATE"], ENV["MODE"])
9
+ end
10
+ end
11
+ end
12
+
13
+ namespace :freeze do
14
+
15
+ desc "freeze a gem locally. Usage: rake freeze:gem GEM=git://github.com/myobie/merb_paginate.git "
16
+ task :gem do
17
+ raise "Please specify the gem you want to freeze using GEM=git://github.com/myobie/merb_paginate.git or GEM=merbful_authentication" unless ENV["GEM"]
18
+ Freezer.freeze(ENV["GEM"], ENV["UPDATE"], ENV["MODE"])
19
+ end
20
+
21
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb-freezer" do
4
+
5
+ before(:each) do
6
+ FileUtils.rm_rf('framework')
7
+ FileUtils.rm_rf('gems')
8
+ end
9
+
10
+ after(:all) do
11
+ FileUtils.rm_rf('framework')
12
+ FileUtils.rm_rf('gems')
13
+ end
14
+
15
+ it "should have a reference to all the git repos" do
16
+ Freezer.components.should be_an_instance_of(Hash)
17
+ component_repos = Freezer.components
18
+ ["core", "more", "plugins"].each do |component|
19
+ component_repos[component].should match(/git:\/\/.+/)
20
+ end
21
+ end
22
+
23
+ it "should have a reference to the framework dir" do
24
+ Freezer.framework_dir.should_not be_nil
25
+ end
26
+
27
+ it "should have a reference to the gems dir" do
28
+ Freezer.gems_dir.should_not be_nil
29
+ end
30
+
31
+ it "should have a reference to the component freezing dir" do
32
+ mr_freeze = Freezer.new('core')
33
+ mr_freeze.freezer_dir.should == Freezer.framework_dir
34
+
35
+ mrs_freeze = Freezer.new('matt-mojo')
36
+ mrs_freeze.freezer_dir.should == Freezer.gems_dir
37
+ end
38
+
39
+ it "should be able to freeze a component using rubygems" do
40
+ mr_freeze = Freezer.new('core', nil, 'rubygems')
41
+ mr_freeze.mode.should == 'rubygems'
42
+ mr_freeze.freeze
43
+ File.exists?('framework').should be_true
44
+ File.exists?('framework/gems').should be_true
45
+ end
46
+
47
+ it "should be able to freeze a component using submodules" do
48
+ mr_freeze = Freezer.new('core')
49
+ mr_freeze.framework_component?.should be_true
50
+ mr_freeze.mode.should == 'submodules'
51
+ # can't be tested since it needs to run from the toplevel of the working tree and I don't want to mess up the rest of the gems by accident
52
+ # mr_freeze.freeze.should_not raise_error
53
+ # File.exists?('framework/merb-core').should be_true
54
+ # File.exists?('.gitmodules').should be_true
55
+ end
56
+
57
+ it "should be able to freeze a a non merb component gem using rubygems" do
58
+ mr_freeze = Freezer.new('googlecharts')
59
+ mr_freeze.framework_component?.should be_false
60
+ mr_freeze.component.should == 'googlecharts'
61
+ mr_freeze.mode.should == 'rubygems'
62
+ mr_freeze.freeze
63
+ File.exists?('gems').should be_true
64
+ File.exists?('gems/gems/googlecharts-1.1.0').should be_true
65
+ end
66
+
67
+ end
@@ -0,0 +1,3 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'merb-freezer'
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-freezer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.3
5
+ platform: ruby
6
+ authors:
7
+ - Matt Aimonetti
8
+ autorequire: merb-freezer
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-04 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Merb plugin that let's you freeze Merb
17
+ email: mattaimonetti@gmail.com
18
+ executables:
19
+ - frozen-merb
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ - TODO
26
+ files:
27
+ - LICENSE
28
+ - README
29
+ - Rakefile
30
+ - TODO
31
+ - lib/merb-freezer
32
+ - lib/merb-freezer/freezer.rb
33
+ - lib/merb-freezer/freezer_mode.rb
34
+ - lib/merb-freezer/merbtasks.rb
35
+ - lib/merb-freezer.rb
36
+ - spec/merb-freezer_spec.rb
37
+ - spec/spec_helper.rb
38
+ has_rdoc: true
39
+ homepage: http://www.merbivore.com
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.0.1
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Merb plugin that let's you freeze Merb
64
+ test_files: []
65
+