rake-distribute 1.0.0.20130321034642

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem "minitest", ">= 4.1.0"
6
+ gem "turn", ">= 0.8.3"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rake-distribute (1.0.0.20121030083712)
5
+ diffy (>= 2.0.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.4.3)
11
+ diffy (2.1.0)
12
+ hoe (3.3.1)
13
+ rake (>= 0.8, < 11.0)
14
+ json (1.7.5)
15
+ json_pure (1.7.5)
16
+ minitest (4.3.1)
17
+ rake (10.0.2)
18
+ rdoc (3.12)
19
+ json (~> 1.4)
20
+ rubyforge (2.0.4)
21
+ json_pure (>= 1.1.7)
22
+ turn (0.9.6)
23
+ ansi
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ hoe (~> 3.1)
30
+ minitest (>= 4.1.0)
31
+ rake-distribute!
32
+ rdoc (~> 3.10)
33
+ rubyforge (>= 2.0.4)
34
+ turn (>= 0.8.3)
data/History.txt ADDED
@@ -0,0 +1,12 @@
1
+ === 1.0.0 / 2012-10-24
2
+
3
+ * 3 minor enhancement
4
+
5
+ * add file install options
6
+ * erb item
7
+ * file item
8
+
9
+ * 1 major enhancement
10
+
11
+ * Birthday!
12
+
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ .autotest
2
+ Gemfile
3
+ Gemfile.lock
4
+ History.txt
5
+ Manifest.txt
6
+ README.txt
7
+ Rakefile
8
+ lib/rake/distribute.rb
9
+ lib/rake/distribute/core.rb
10
+ lib/rake/distribute/dsl.rb
11
+ lib/rake/distribute/error.rb
12
+ lib/rake/distribute/item.rb
13
+ lib/rake/distribute/item/erbfile.rb
14
+ lib/rake/distribute/item/file.rb
15
+ lib/rake/distribute/version.rb
16
+ test/minitest_helper.rb
17
+ test/test_rake_distribute.rb
data/README.txt ADDED
@@ -0,0 +1,70 @@
1
+ = rake-distribute
2
+
3
+ * https://github.com/zhaocai/rake-distribute
4
+
5
+ == DESCRIPTION:
6
+
7
+ generate rake install/uninstall/diff/... tasks to distribute items (files, templates, directories, etc.) to difference locations.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * `bundle install` can handle the required gems
20
+
21
+ == INSTALL:
22
+
23
+ * gem install rake-distribute
24
+
25
+ == USAGE:
26
+
27
+ distribute :FileItem do
28
+ from "/path/from"
29
+ to "/path/to"
30
+ end
31
+
32
+ distribute :ErbFile do
33
+ from "/path/from"
34
+ to "/path/to"
35
+ with_context {:a => 1, :b => 2}
36
+ end
37
+
38
+ == DEVELOPERS:
39
+
40
+ After checking out the source, run:
41
+
42
+ $ rake newb
43
+
44
+ This task will install any missing dependencies, run the tests/specs,
45
+ and generate the RDoc.
46
+
47
+ == LICENSE:
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) 2012, Zhao Cai
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
4
+
5
+ require 'hoe'
6
+
7
+ # $DEBUG = true
8
+
9
+ Hoe.plugin :gemspec
10
+ Hoe.plugin :git
11
+ Hoe.plugin :bundler
12
+ Hoe.plugin :test
13
+ # Hoe.plugin :rubyforge
14
+ # Hoe.plugin :compiler
15
+ # Hoe.plugin :email
16
+ # Hoe.plugin :gem_prelude_sucks
17
+ # Hoe.plugin :inline
18
+ # Hoe.plugin :perforce
19
+ # Hoe.plugin :racc
20
+ # Hoe.plugin :rcov
21
+ # Hoe.plugin :seattlerb
22
+ Hoe.plugin :rubygems
23
+
24
+ Hoe.spec 'rake-distribute' do
25
+ self.rubyforge_name = 'zhaowu'
26
+ developer 'Zhao Cai', 'caizhaoff@gmail.com'
27
+ # self.rubyforge_name = 'rake-distributex' # if different than 'rake-distribute'
28
+
29
+ # extra_deps << ['diffy', '>= 2.0.9']
30
+ end
31
+
32
+
33
+
34
+ # vim: syntax=ruby
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rake'
5
+ require 'diffy'
6
+ require 'rake/distribute/version'
7
+
8
+ require 'rake/distribute/core'
9
+ require 'rake/distribute/dsl'
10
+
11
+ require 'rake/distribute/item'
12
+ require 'rake/distribute/item/file'
13
+ require 'rake/distribute/item/erbfile'
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake/dsl_definition'
3
+ require 'singleton'
4
+
5
+ module Rake::Distribute
6
+
7
+ class Core
8
+ include Singleton
9
+ include Rake::DSL
10
+
11
+ attr_accessor :build_dir
12
+ attr_accessor :distribute_config_file
13
+ attr_accessor :items
14
+
15
+
16
+ def initialize
17
+ @items = []
18
+
19
+ # unify task descriptions
20
+ namespace :distribute do
21
+ desc "distribute"
22
+ task :install
23
+
24
+ desc "build for distribution"
25
+ task :build
26
+
27
+ desc "clean temporary items"
28
+ task :clean
29
+
30
+ desc "clean all unnecessary items"
31
+ task :clobber => :clean
32
+
33
+ desc "diff the distributed from the source"
34
+ task :diff
35
+
36
+ desc "uninstall the distributed"
37
+ task :uninstall
38
+ end
39
+ task :clean => "distribute:clean"
40
+ task :clobber => "distribute:clobber"
41
+ end
42
+
43
+ def distribute(item_class, &block)
44
+ item = get_item_class(item_class).new(&block)
45
+ item.sanity?
46
+ item.define_tasks
47
+ @items << item
48
+ end
49
+
50
+ private
51
+
52
+ def get_item_class(item_class)
53
+ Rake::Distribute::Item.const_get(item_class)
54
+ end
55
+ end
56
+
57
+ end
58
+
@@ -0,0 +1,24 @@
1
+ module Rake::Distribute
2
+ # Adds `distribute` method to the top-level namespace.
3
+ module DSL
4
+ # Distribute an item to some place
5
+ #
6
+ # ## Examples:
7
+ #
8
+ # distribute :FileItem do
9
+ # from "/path/from"
10
+ # to "/path/to"
11
+ # end
12
+ #
13
+ # distribute :ErbFile do
14
+ # from "/path/from"
15
+ # to "/path/to"
16
+ # with_context {:a => 1, :b => 2}
17
+ # end
18
+ def distribute(item_class, &block)
19
+ Rake::Distribute::Core.instance.distribute(item_class, &block)
20
+ end
21
+ end
22
+ end
23
+
24
+ self.extend Rake::Distribute::DSL
@@ -0,0 +1,3 @@
1
+ module Rake::Distribute
2
+ class TimeoutError < RuntimeError ; end
3
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rake/dsl_definition'
4
+
5
+ module Rake::Distribute
6
+ module Item
7
+ @@serial_number = 0
8
+ def self.sn
9
+ @@serial_number += 1
10
+ end
11
+
12
+ class Base
13
+ include Rake::DSL
14
+
15
+ def initialize(&block)
16
+ instance_eval(&block) if block_given?
17
+ end
18
+
19
+ def from(source)
20
+ @src = source
21
+ end
22
+
23
+ def to(dest, options={})
24
+ @dest = dest
25
+ end
26
+
27
+ def diff(&block)
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def sanity?
32
+ raise SyntaxError, "from: is not defined" unless defined? @src
33
+ raise SyntaxError, "to: is not defined" unless defined? @dest
34
+ end
35
+
36
+ def define_tasks
37
+ raise NotImplementedError
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,85 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake/distribute/item/file'
3
+ require 'rake/ext/string'
4
+ require 'erb'
5
+ require 'ostruct'
6
+
7
+ module Rake::Distribute
8
+ module Item
9
+
10
+ class ErbContext < OpenStruct
11
+ def get_binding
12
+ binding
13
+ end
14
+ end
15
+
16
+ class ErbFile < FileItem
17
+ def initialize(&block)
18
+ @context = {}
19
+ @build_dir = File.join('build','distribute')
20
+ super
21
+ end
22
+
23
+ def sanity?
24
+ super
25
+ raise ArgumentError, "#{@src} does not exist!" unless File.exists?(@src)
26
+ end
27
+
28
+ def build_dir(folder)
29
+ @build_dir = folder
30
+ end
31
+
32
+ def with_context(context)
33
+ @context = context
34
+ end
35
+
36
+ def define_tasks
37
+ namespace "distribute" do
38
+ dest_dir = @dest.pathmap("%d")
39
+ directory dest_dir
40
+ directory @build_dir
41
+
42
+ build_file = File.join(@build_dir,
43
+ "#{Item.sn.to_s}-#{@src.pathmap('%n')}")
44
+ file build_file => @src do
45
+ File.open(build_file, 'w') do |f|
46
+ erb = ERB.new(File.read(@src))
47
+ f.write(erb.result(ErbContext.new(@context).get_binding))
48
+ f.flush
49
+ end
50
+ end
51
+
52
+ file @dest => build_file do
53
+ install build_file, @dest, @dest_options
54
+ end
55
+
56
+ task :build => [@build_dir, build_file]
57
+ task :install => [@build_dir, build_file, dest_dir, @dest]
58
+
59
+ task :uninstall do
60
+ safe_unlink @dest if File.exists?(@dest)
61
+ end
62
+
63
+ task :clean do
64
+ safe_unlink build_file if File.exists?(build_file)
65
+ end
66
+
67
+ task :clobber => [:clean] do
68
+ rmdir @build_dir
69
+ end
70
+
71
+ task :diff => [@build_dir, build_file] do
72
+ diff = Diffy::Diff.new(
73
+ @dest, build_file, :source => 'files', :allow_empty_diff => true
74
+ ).to_s(:text)
75
+
76
+ @diff_proc.call(@dest, build_file) unless diff.empty?
77
+ end
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+ end
85
+
@@ -0,0 +1,54 @@
1
+ require 'rake/distribute/item'
2
+ require 'diffy'
3
+
4
+ module Rake::Distribute
5
+ module Item
6
+
7
+ class FileItem < Base
8
+ def initialize(&block)
9
+ @diff_proc = Proc.new {|dest,src| puts "#{dest} differs from #{src}"}
10
+ super
11
+ end
12
+
13
+ def sanity?
14
+ super
15
+ raise ArgumentError, "#{@src} does not exist!" unless File.exists?(@src)
16
+ end
17
+
18
+ def to(dest, options={})
19
+ @dest = dest
20
+ @dest_options = options
21
+ end
22
+
23
+ def diff(&block)
24
+ @diff_proc = block if block_given?
25
+ end
26
+
27
+ def define_tasks
28
+ namespace "distribute" do
29
+ dest_folder = @dest.pathmap("%d")
30
+ directory dest_folder
31
+ file @dest => @src do
32
+ install @src, @dest, @dest_options
33
+ end
34
+
35
+ task :install => [dest_folder, @dest]
36
+
37
+ task :uninstall do
38
+ safe_unlink @dest
39
+ end
40
+
41
+ task :diff do
42
+ diff = Diffy::Diff.new(
43
+ @dest, @src, :source => 'files', :allow_empty_diff => true
44
+ ).to_s(:text)
45
+
46
+ @diff_proc.call(@dest, @src) unless diff.empty?
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Rake::Distribute
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'turn/autorun'
2
+
3
+ Turn.config do |c|
4
+ # use one of output formats:
5
+ # :outline - turn's original case/test outline mode [default]
6
+ # :progress - indicates progress with progress bar
7
+ # :dotted - test/unit's traditional dot-progress mode
8
+ # :pretty - new pretty reporter
9
+ # :marshal - dump output as YAML (normal run mode only)
10
+ # :cue - interactive testing
11
+ c.format = :outline
12
+ # turn on invoke/execute tracing, enable full backtrace
13
+ c.trace = true
14
+ # use humanized test names (works only with :outline format)
15
+ c.natural = true
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'rake/distribute'
3
+ # require "minitest_helper"
4
+
5
+
6
+ class RakeDistributeTestCase < MiniTest::Unit::TestCase
7
+ def setup
8
+ self.extend Rake::Distribute::DSL
9
+ end
10
+
11
+ def test_sanity
12
+ assert_raises(ArgumentError) {
13
+ distribute :FileItem do
14
+ from "/non-exist/file/path"
15
+ to "/some/place"
16
+ end
17
+ }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-distribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.20130321034642
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zhao Cai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hoe
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.3'
46
+ description: generate rake install/uninstall/diff/... tasks to distribute items (files,
47
+ templates, directories, etc.) to difference locations.
48
+ email:
49
+ - caizhaoff@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ files:
57
+ - .autotest
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.txt
63
+ - Rakefile
64
+ - lib/rake/distribute.rb
65
+ - lib/rake/distribute/core.rb
66
+ - lib/rake/distribute/dsl.rb
67
+ - lib/rake/distribute/error.rb
68
+ - lib/rake/distribute/item.rb
69
+ - lib/rake/distribute/item/erbfile.rb
70
+ - lib/rake/distribute/item/file.rb
71
+ - lib/rake/distribute/version.rb
72
+ - test/minitest_helper.rb
73
+ - test/test_rake_distribute.rb
74
+ homepage: https://github.com/zhaocai/rake-distribute
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --main
79
+ - README.txt
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: zhaowu
96
+ rubygems_version: 1.8.24
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: generate rake install/uninstall/diff/..
100
+ test_files:
101
+ - test/test_rake_distribute.rb
102
+ has_rdoc: