thorero-freezer 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,35 @@
1
+ merb-freezer
2
+ ============
3
+
4
+ <<<<<<< HEAD:merb-freezer/README
5
+ This plugin lets you freeze Merb and run it using the frozen gems.
6
+
7
+ ==Why would you want to freeze Merb?
8
+
9
+ * You might have multiple applications on the same server/slice/cluster. Different applications might require different versions of Merb.
10
+
11
+ * You might work with a team of developers and want everyone to be using the same Merb version.
12
+
13
+ * You are using Merb Edge, you want to make sure the production server and your co workers are developing/testing against the same revision.
14
+
15
+
16
+ ==What are your options?
17
+
18
+ * You just want to lock your app to a specific version. For instance version merb-core 0.9.2
19
+
20
+ * You only want to use frozen gems located in /framework or /gems
21
+
22
+
23
+ == How to lock your app?
24
+
25
+ TODO
26
+
27
+ == How to use frozen gems
28
+
29
+ Instead of starting merb by typing "merb" in your console, type "frozen-merb" and that's it :)
30
+
31
+
32
+ If frozen-merb can't find frozen gems in /framework or /gems then Merb will start normally using the system's gems.
33
+ =======
34
+ see README.markdown
35
+ >>>>>>> new_merb_gen:merb-freezer/README
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require "extlib"
4
+ require 'merb-core/tasks/merb_rake_helper'
5
+
6
+ ##############################################################################
7
+ # Package && release
8
+ ##############################################################################
9
+ RUBY_FORGE_PROJECT = "thorero"
10
+ PROJECT_URL = "http://merbivore.com"
11
+ PROJECT_SUMMARY = "Merb plugin that let's you freeze Merb"
12
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
13
+
14
+ GEM_AUTHOR = "Matt Aimonetti"
15
+ GEM_EMAIL = "mattaimonetti@gmail.com"
16
+
17
+ GEM_NAME = "thorero-freezer"
18
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
19
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
20
+
21
+ RELEASE_NAME = "REL #{GEM_VERSION}"
22
+
23
+ require "extlib/tasks/release"
24
+
25
+ spec = Gem::Specification.new do |s|
26
+ s.rubyforge_project = RUBY_FORGE_PROJECT
27
+ s.name = GEM_NAME
28
+ s.version = GEM_VERSION
29
+ s.platform = Gem::Platform::RUBY
30
+ s.has_rdoc = true
31
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
32
+ s.summary = PROJECT_SUMMARY
33
+ s.description = PROJECT_DESCRIPTION
34
+ s.author = GEM_AUTHOR
35
+ s.email = GEM_EMAIL
36
+ s.homepage = PROJECT_URL
37
+ s.add_dependency('merb-core', ">= #{GEM_VERSION}")
38
+ s.require_path = 'lib'
39
+ s.bindir = "bin"
40
+ s.executables = %w( frozen-merb )
41
+ s.autorequire = 'merb-freezer'
42
+ s.require_path = 'lib'
43
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
44
+ end
45
+
46
+ Rake::GemPackageTask.new(spec) do |pkg|
47
+ pkg.gem_spec = spec
48
+ end
49
+
50
+ desc "Install the gem"
51
+ task :install => [:package] do
52
+ sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
53
+ end
54
+
55
+ namespace :jruby do
56
+
57
+ desc "Run :package and install the resulting .gem with jruby"
58
+ task :install => :package do
59
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
60
+ end
61
+
62
+ end
63
+
64
+
65
+ require 'rubygems'
66
+ require "merb-core"
67
+ require 'rake/gempackagetask'
68
+ require "spec/rake/spectask"
69
+ require 'merb-core/tasks/merb_rake_helper'
70
+
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ TODO:
2
+ Fix LICENSE with your name
3
+ Fix Rakefile with your name and contact info
4
+ Add your code to lib/merb-freezer.rb
5
+ Add your Merb rake tasks to lib/merb-freezer/merbtasks.rb
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ root = nil
3
+ %w[-m --merb-root].detect { |o| root = ARGV.index(o) }
4
+ __DIR__ = root ? ARGV[root+1] : Dir.getwd
5
+
6
+ framework = File.join(__DIR__,"framework")
7
+
8
+ # load merb from the framework folder
9
+
10
+ if File.directory?(framework)
11
+ puts "Running from frozen framework"
12
+ core = File.join(framework,"merb-core")
13
+ if File.directory?(core)
14
+ puts "using merb-core from #{core}"
15
+ $:.unshift File.join(core,"lib")
16
+ end
17
+ more = File.join(framework,"merb-more")
18
+ if File.directory?(more)
19
+ Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
20
+ $:.unshift File.join(more,d,'lib')
21
+ end
22
+ end
23
+ plugins = File.join(framework,"merb-plugins")
24
+ if File.directory?(plugins)
25
+ Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
26
+ $:.unshift File.join(plugins,d,'lib')
27
+ end
28
+ end
29
+ require "merb-core/core_ext/kernel"
30
+ require "merb-core/core_ext/rubygems"
31
+ else
32
+ # load from the gems folder
33
+ gem = Dir["./gems/gems/merb-core-*"].last
34
+ if gem
35
+ require gem + "/lib/merb-core/core_ext/kernel"
36
+ require gem + "/lib/merb-core/core_ext/rubygems"
37
+
38
+ Gem.clear_paths
39
+ Gem.path.unshift(__DIR__+"/gems")
40
+ else
41
+ puts "Can't run frozen Merb from framework/ and/or gems/ please freeze Merb"
42
+ puts "Merb will try to start using the system gems"
43
+ end
44
+ end
45
+
46
+ # load submodule gems
47
+ gem_submodules_dir = File.join(__DIR__,"gems/submodules")
48
+ if File.directory?(gem_submodules_dir)
49
+ Dir["#{gem_submodules_dir}/*"].each do |dir|
50
+ $:.unshift File.join(dir,"lib")
51
+ end
52
+ end
53
+
54
+ require 'merb-core'
55
+ unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
56
+ ARGV.push *%w[-a mongrel]
57
+ end
58
+
59
+ Merb.frozen! if (File.directory?(framework) || gem)
60
+ 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,75 @@
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 "freezing mode: #{@mode}"
67
+ send "#{@mode}_freeze"
68
+ end
69
+
70
+ # Returns true if the gem is part of the Merb components
71
+ def framework_component?
72
+ Freezer.components.keys.include?(@component.gsub("merb-", ""))
73
+ end
74
+
75
+ end
@@ -0,0 +1,116 @@
1
+ require 'find'
2
+ require 'rubygems'
3
+ require 'rubygems/dependency_installer'
4
+
5
+ module FreezerMode
6
+
7
+ def sudo
8
+ windows = (PLATFORM =~ /win32|cygwin/) rescue nil
9
+ sudo = windows ? "" : "sudo"
10
+ end
11
+
12
+ def gitmodules
13
+ File.join(Dir.pwd, ".gitmodules")
14
+ end
15
+
16
+ # Uses the Git submodules to freeze a component
17
+ #
18
+ def submodules_freeze
19
+ # Ensure that required git commands are available
20
+ %w(git-pull git-submodule).each do |bin|
21
+ next if in_path?(bin)
22
+ $stderr.puts "ERROR: #{bin} must be avaible in PATH - you might want to freeze using MODE=rubygems"
23
+ exit 1
24
+ end
25
+
26
+ # Create directory to receive the frozen components
27
+ create_freezer_dir(freezer_dir)
28
+
29
+ if managed?(@component)
30
+ puts "#{@component} seems to be already managed by git-submodule."
31
+ if @update
32
+ puts "Trying to update #{@component} ..."
33
+ `cd #{freezer_dir}/#{@component} && git-pull`
34
+ else
35
+ puts "you might want to call this rake task using UPDATE=true if you wish to update the frozen gems using this task"
36
+ end
37
+ else
38
+ puts "Creating submodule for #{@component} ..."
39
+ if framework_component?
40
+ `cd #{Dir.pwd} & git-submodule --quiet add #{Freezer.components[@component.gsub("merb-", '')]} #{File.basename(freezer_dir)}/#{@component}`
41
+ else
42
+ `cd #{Dir.pwd} & git-submodule --quiet add #{@component} gems/submodules/#{@component.match(/.*\/(.*)\..{3}$/)[1]}`
43
+ end
44
+ if $?.success?
45
+ `git-submodule init`
46
+ else
47
+ # Should this instead be a raise?
48
+ $stderr.puts("ERROR: unable to create submodule for #{@component} - you might want to freeze using MODE=rubygems (make sure the current project has a git repository)")
49
+ end
50
+ end
51
+ end
52
+
53
+ # Uses rubygems to freeze the components locally
54
+ def rubygems_freeze
55
+ create_freezer_dir(freezer_dir)
56
+ puts "Install #{@component} and dependencies from rubygems"
57
+ if File.exist?(freezer_dir) && !File.writable?("#{freezer_dir}/cache")
58
+ puts "you might want to CHOWN the gems folder so it's not owned by root: sudo chown -R #{`whoami`} #{freezer_dir}"
59
+ end
60
+ install_rubygem @component
61
+ end
62
+
63
+ # Install a gem - looks remotely and locally
64
+ # won't process rdoc or ri options.
65
+ def install_rubygem(gem, version = nil)
66
+ Gem.configuration.update_sources = false
67
+ Gem.clear_paths
68
+ installer = Gem::DependencyInstaller.new(:install_dir => freezer_dir)
69
+ exception = nil
70
+ begin
71
+ installer.install gem, version
72
+ rescue Gem::InstallError => e
73
+ exception = e
74
+ rescue Gem::GemNotFoundException => e
75
+ puts "Locating #{gem} in local gem path cache..."
76
+ spec = version ? Gem.cache.find_name(gem, "= #{version}").first : Gem.cache.find_name(gem).sort_by { |g| g.version }.last
77
+ if spec && File.exists?(gem_file = spec.installation_path / 'cache' / "#{spec.full_name}.gem")
78
+ installer.install gem_file
79
+ end
80
+ exception = e
81
+ end
82
+ if installer.installed_gems.empty? && e
83
+ puts "Failed to install gem '#{gem}' (#{e.message})"
84
+ end
85
+ installer.installed_gems.each do |spec|
86
+ puts "Successfully installed #{spec.full_name}"
87
+ end
88
+ end
89
+
90
+ def create_freezer_dir(path)
91
+ unless File.directory?(path)
92
+ puts "Creating freezer directory ..."
93
+ FileUtils.mkdir_p(path)
94
+ end
95
+ end
96
+
97
+ protected
98
+
99
+ # returns true if submodules are used
100
+ def in_submodule?(component)
101
+ return false unless File.exists?(gitmodules)
102
+ # File.read(gitmodules) =~ %r![submodule "#{freezer_dir}/#{component}"]!
103
+ File.read(gitmodules).match(%r!#{freezer_dir}/#{component}!)
104
+ end
105
+
106
+ # returns true if the component is in a submodule
107
+ def managed?(component)
108
+ File.directory?(File.join(freezer_dir, component)) || in_submodule?(component)
109
+ end
110
+
111
+ def in_path?(bin)
112
+ `which #{bin}`
113
+ !$?.nil? && $?.success?
114
+ end
115
+
116
+ end
@@ -0,0 +1,28 @@
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
+ desc "freeze all merb components (core, more, plugins) - use MODE=rubgygems and UPDATE=true as in regular freezing tasks"
22
+ task :all do
23
+ ['core', 'more', 'plugins'].each do |component|
24
+ Freezer.freeze(component, ENV["UPDATE"], ENV["MODE"])
25
+ end
26
+ end
27
+
28
+ 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
+ Dir['gems/gems/googlecharts-1.*'].join(' ').include?('gems/gems/googlecharts-').should be_true
65
+ end
66
+
67
+ end
@@ -0,0 +1,7 @@
1
+ $TESTING=true
2
+ <<<<<<< HEAD:merb-freezer/spec/spec_helper.rb
3
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
4
+ =======
5
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
6
+ require 'merb-freezer'
7
+ >>>>>>> new_merb_gen:merb-freezer/spec/spec_helper.rb
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thorero-freezer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4
5
+ platform: ruby
6
+ authors:
7
+ - Matt Aimonetti
8
+ autorequire: merb-freezer
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-02 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.4
24
+ version:
25
+ description: Merb plugin that let's you freeze Merb
26
+ email: mattaimonetti@gmail.com
27
+ executables:
28
+ - frozen-merb
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - LICENSE
34
+ - TODO
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - TODO
40
+ - lib/merb-freezer
41
+ - lib/merb-freezer/freezer.rb
42
+ - lib/merb-freezer/freezer_mode.rb
43
+ - lib/merb-freezer/merbtasks.rb
44
+ - lib/merb-freezer.rb
45
+ - spec/merb-freezer_spec.rb
46
+ - spec/spec_helper.rb
47
+ has_rdoc: true
48
+ homepage: http://merbivore.com
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: thorero
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Merb plugin that let's you freeze Merb
73
+ test_files: []
74
+