falkorlib 0.1.0

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/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ ##############################################################################
2
+ # Rakefile - Configuration file for rake (http://rake.rubyforge.org/)
3
+ # Time-stamp: <Lun 2014-06-02 14:58 svarrette>
4
+ #
5
+ # Copyright (c) 2012 Sebastien Varrette <Sebastien.Varrette@uni.lu>
6
+ # . http://varrette.gforge.uni.lu
7
+ # ____ _ __ _ _
8
+ # | _ \ __ _| | _____ / _(_) | ___
9
+ # | |_) / _` | |/ / _ \ |_| | |/ _ \
10
+ # | _ < (_| | < __/ _| | | __/
11
+ # |_| \_\__,_|_|\_\___|_| |_|_|\___|
12
+ #
13
+ # Use 'rake -T' to list the available actions
14
+ #
15
+ # Resources:
16
+ # * http://www.stuartellis.eu/articles/rake/
17
+ ##############################################################################
18
+ require "bundler/gem_tasks"
19
+
20
+
21
+ # We run tests by default
22
+ task :default => :test
23
+
24
+ #
25
+ # Install all tasks found in tasks folder
26
+ #
27
+ # See .rake files there for complete documentation.
28
+ #
29
+ RAKE_TASKS_TO_LOAD = [
30
+ #'debug_mail.rake',
31
+ 'gem.rake',
32
+ 'spec_test.rake',
33
+ #'unit_test.rake',
34
+ 'yard.rake'
35
+ ]
36
+
37
+ Dir["tasks/*.rake"].each do |taskfile|
38
+ next unless RAKE_TASKS_TO_LOAD.include?(taskfile.gsub(/.*tasks\//, ''))
39
+ load taskfile
40
+ end
41
+
42
+ desc "clean the directory"
43
+ task :clean => :clobber_package do
44
+ sh "rm -rf doc" if File.directory?("doc")
45
+ end
data/falkorlib.gemspec ADDED
@@ -0,0 +1,207 @@
1
+ # -*- coding: utf-8 -*-
2
+ # We require your library, mainly to have access to the VERSION number.
3
+ # Feel free to set $version manually.
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
5
+ require "falkorlib/version"
6
+ $version = FalkorLib::Version.to_s
7
+
8
+ #
9
+ # This is your Gem specification. Default values are provided so that your library
10
+ # should be correctly packaged given what you have described in the .noespec file.
11
+ #
12
+ Gem::Specification.new do |s|
13
+
14
+ ################################################################### ABOUT YOUR GEM
15
+
16
+ # Gem name (required)
17
+ s.name = "falkorlib"
18
+
19
+ # Gem version (required)
20
+ s.version = $version
21
+
22
+ # A short summary of this gem
23
+ #
24
+ # This is displayed in `gem list -d`.
25
+ s.summary = "Sebastien Varrette aka Falkor's Common library to share Ruby code and {rake,cap} tasks"
26
+
27
+ # A long description of this gem (required)
28
+ #
29
+ # The description should be more detailed than the summary. For example,
30
+ # you might wish to copy the entire README into the description.
31
+ s.description = "This is my personal library I use to share the Ruby tidbits, Rake and Capistrano tasks I made for my various projects. \nThis is also my first gem so any comments on the code/organization are welcome, I'm a newbie in this domain. \nNote that I used [Noe](https://github.com/blambeau/noe) to bootstrap this project and get a fully documented environment."
32
+
33
+ # The URL of this gem home page (optional)
34
+ s.homepage = "https://github.com/Falkor/falkorlib"
35
+
36
+ # Gem publication date (required but auto)
37
+ #
38
+ # Today is automatically used by default, uncomment only if
39
+ # you know what you do!
40
+ #
41
+ # s.date = Time.now.strftime('%Y-%m-%d')
42
+
43
+ # The license(s) for the library. Each license must be a short name, no
44
+ # more than 64 characters.
45
+ #
46
+ s.licenses = ['MIT']
47
+
48
+ # The rubyforge project this gem lives under (optional)
49
+ #
50
+ # s.rubyforge_project = nil
51
+
52
+ ################################################################### ABOUT THE AUTHORS
53
+
54
+ # The list of author names who wrote this gem.
55
+ #
56
+ # If you are providing multiple authors and multiple emails they should be
57
+ # in the same order.
58
+ #
59
+ s.authors = ["Sebastien Varrette"]
60
+
61
+ # Contact emails for this gem
62
+ #
63
+ # If you are providing multiple authors and multiple emails they should be
64
+ # in the same order.
65
+ #
66
+ # NOTE: Somewhat strangly this attribute is always singular!
67
+ # Don't replace by s.emails = ...
68
+ s.email = ["Sebastien.Varrette@uni.lu"]
69
+
70
+ ################################################################### PATHS, FILES, BINARIES
71
+
72
+ # Paths in the gem to add to $LOAD_PATH when this gem is
73
+ # activated (required).
74
+ #
75
+ # The default 'lib' is typically sufficient.
76
+ s.require_paths = ["lib"]
77
+
78
+ # Files included in this gem.
79
+ #
80
+ # By default, we take all files included in the .Manifest.txt file on root
81
+ # of the project. Entries of the manifest are interpreted as Dir[...]
82
+ # patterns so that lazy people may use wilcards like lib/**/*
83
+ #
84
+ here = File.expand_path(File.dirname(__FILE__))
85
+ s.files = File.readlines(File.join(here, '.Manifest.txt')).
86
+ inject([]){|files, pattern| files + Dir[File.join(here, pattern.strip)]}.
87
+ collect{|x| x[(1+here.size)..-1]}
88
+
89
+ # Test files included in this gem.
90
+ #
91
+ s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
92
+
93
+ # Alternative:
94
+ #s.files = `git ls-files`.split("\n")
95
+ #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
96
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
97
+
98
+
99
+
100
+
101
+ # The path in the gem for executable scripts (optional)
102
+ #
103
+ #s.bindir = "bin"
104
+
105
+ # Executables included in the gem.
106
+ #
107
+ #s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
108
+
109
+ ################################################################### REQUIREMENTS & INSTALL
110
+ # Remember the gem version requirements operators and schemes:
111
+ # = Equals version
112
+ # != Not equal to version
113
+ # > Greater than version
114
+ # < Less than version
115
+ # >= Greater than or equal to
116
+ # <= Less than or equal to
117
+ # ~> Approximately greater than
118
+ #
119
+ # Don't forget to have a look at http://lmgtfy.com/?q=Ruby+Versioning+Policies
120
+ # for setting your gem version.
121
+ #
122
+ # For your requirements to other gems, remember that
123
+ # ">= 2.2.0" (optimistic: specify minimal version)
124
+ # ">= 2.2.0", "< 3.0" (pessimistic: not greater than the next major)
125
+ # "~> 2.2" (shortcut for ">= 2.2.0", "< 3.0")
126
+ # "~> 2.2.0" (shortcut for ">= 2.2.0", "< 2.3.0")
127
+ #
128
+ #s.add_dependency("rake", ">= 10.1.0")
129
+ s.add_runtime_dependency 'rake', '~> 10.1', '>= 10.1.0'
130
+ s.add_runtime_dependency 'git_remote_branch', '~> 0'
131
+ #s.add_dependency("git_remote_branch")
132
+ s.add_runtime_dependency 'git', '~> 1.2', '>= 1.2.5'
133
+ s.add_dependency("term-ansicolor", "~> 1.3")
134
+
135
+ #
136
+ # One call to add_dependency('gem_name', 'gem version requirement') for each
137
+ # runtime dependency. These gems will be installed with your gem.
138
+ # One call to add_development_dependency('gem_name', 'gem version requirement')
139
+ # for each development dependency. These gems are required for developers
140
+ #
141
+ #s.add_development_dependency("rake", ">= 10.1.0") #"~> 0.9.2")
142
+ s.add_development_dependency("bundler", "~> 1.0")
143
+ s.add_development_dependency 'rspec', '~> 2.7', '>= 2.7.0'
144
+ s.add_development_dependency("pry", "~> 0.9")
145
+ s.add_development_dependency("yard", "~> 0.8")
146
+ s.add_development_dependency("awesome_print", "~> 1.2")
147
+ #s.add_development_dependency("bluecloth", "~> 2.2.0")
148
+ #s.add_development_dependency("wlang", "~> 0.10.2")
149
+
150
+
151
+ # The version of ruby required by this gem
152
+ #
153
+ # Uncomment and set this if your gem requires specific ruby versions.
154
+ #
155
+ # s.required_ruby_version = ">= 0"
156
+
157
+ # The RubyGems version required by this gem
158
+ #
159
+ # s.required_rubygems_version = ">= 0"
160
+
161
+ # The platform this gem runs on. See Gem::Platform for details.
162
+ #
163
+ # s.platform = nil
164
+
165
+ # Extensions to build when installing the gem.
166
+ #
167
+ # Valid types of extensions are extconf.rb files, configure scripts
168
+ # and rakefiles or mkrf_conf files.
169
+ #
170
+ s.extensions = []
171
+
172
+ # External (to RubyGems) requirements that must be met for this gem to work.
173
+ # It’s simply information for the user.
174
+ #
175
+ s.requirements = nil
176
+
177
+ # A message that gets displayed after the gem is installed
178
+ #
179
+ # Uncomment and set this if you want to say something to the user
180
+ # after gem installation
181
+ #
182
+ s.post_install_message = "Thanks for installing FalkorLib.\n"
183
+
184
+ ################################################################### SECURITY
185
+
186
+ # The key used to sign this gem. See Gem::Security for details.
187
+ #
188
+ #s.signing_key = "0xDD01D5C0"
189
+
190
+ # The certificate chain used to sign this gem. See Gem::Security for
191
+ # details.
192
+ #
193
+ # s.cert_chain = []
194
+
195
+ ################################################################### RDOC
196
+
197
+ # An ARGV style array of options to RDoc
198
+ #
199
+ # See 'rdoc --help' about this
200
+ #
201
+ s.rdoc_options = []
202
+
203
+ # Extra files to add to RDoc such as README
204
+ #
205
+ s.extra_rdoc_files = Dir["README.md"] + Dir["CHANGELOG.md"] + Dir["LICENCE.md"]
206
+
207
+ end
data/lib/falkorlib.rb ADDED
@@ -0,0 +1,10 @@
1
+ #
2
+ # Sebastien Varrette aka Falkor's Common library to share Ruby code and `{rake,cap}` tasks
3
+ #
4
+ module FalkorLib
5
+
6
+ end # module FalkorLib
7
+
8
+ require "falkorlib/version"
9
+ require "falkorlib/loader"
10
+ require "falkorlib/common"
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/ruby
2
+
3
+ ### Configure colors ###
4
+ begin
5
+ require 'term/ansicolor'
6
+ COLOR = true
7
+ rescue Exception => e
8
+ puts "/!\\ cannot find the 'term/ansicolor' library"
9
+ puts " Consider installing it by 'gem install term-ansicolor'"
10
+ COLOR = false
11
+ end
12
+
13
+ require 'yaml'
14
+
15
+ module FalkorLib
16
+ module Common
17
+ module_function
18
+ ##################################
19
+ ### Default printing functions ###
20
+ ##################################
21
+
22
+ # Print a text in green
23
+ def green(str)
24
+ COLOR == true ? Term::ANSIColor.green(str) : str
25
+ end
26
+
27
+ # Print a text in red
28
+ def red(str)
29
+ COLOR == true ? Term::ANSIColor.red(str) : str
30
+ end
31
+
32
+ # Print a text in cyan
33
+ def cyan(str)
34
+ COLOR == true ? Term::ANSIColor.cyan(str) : str
35
+ end
36
+
37
+ # Print an info message
38
+ def info(str)
39
+ puts green("[INFO] " + str)
40
+ end
41
+
42
+ # Print an warning message
43
+ def warning(str)
44
+ puts cyan("/!\\ WARNING: " + str)
45
+ end
46
+ def warn(str)
47
+ warning(str)
48
+ end
49
+ ## Print an error message and abort
50
+ def error(str)
51
+ #abort red("*** ERROR *** " + str)
52
+ $stderr.puts red("*** ERROR *** " + str)
53
+ exit 1
54
+ end
55
+ def not_implemented()
56
+ error("NOT YET IMPLEMENTED")
57
+ end
58
+
59
+ ##############################
60
+ ### Interaction functions ###
61
+ ##############################
62
+
63
+ ## Ask a question
64
+ def ask(question, default_answer='')
65
+ print "#{question} "
66
+ print "[Default: #{default_answer}]" unless default_answer == ''
67
+ print ": "
68
+ STDOUT.flush
69
+ answer = STDIN.gets.chomp
70
+ return answer.empty?() ? default_answer : answer
71
+ end
72
+
73
+ ## Ask whether or not to really continue
74
+ def really_continue?(default_answer = 'Yes')
75
+ pattern = (default_answer =~ /yes/i) ? '(Y|n)' : '(y|N)'
76
+ answer = ask( cyan("=> Do you really want to continue #{pattern}?"), default_answer)
77
+ exit 0 if answer =~ /n.*/i
78
+ end
79
+
80
+ ############################
81
+ ### Execution functions ###
82
+ ############################
83
+
84
+ ## Check for the presence of a given command
85
+ def command?(name)
86
+ `which #{name}`
87
+ $?.success?
88
+ end
89
+
90
+ ## Execute a given command - exit if status != 0
91
+ def execute(cmd)
92
+ sh %{#{cmd}} do |ok, res|
93
+ if ! ok
94
+ error("The command '#{cmd}' failed with exit status #{res.exitstatus}")
95
+ end
96
+ end
97
+ end
98
+
99
+ ## "Nice" way to present run commands
100
+ ## Ex: run %{ hostname -f }
101
+ def run(cmds)
102
+ puts bold("[Running]\n#{cmds.gsub(/^\s*/, ' ')}")
103
+ #puts cmds.split(/\n */).inspect
104
+ cmds.split(/\n */).each do |cmd|
105
+ next if cmd.empty?
106
+ system("#{cmd}") unless DEBUG
107
+ end
108
+ end
109
+
110
+ ###############################
111
+ ### YAML File loading/store ###
112
+ ###############################
113
+
114
+ # Return the yaml content as a Hash object
115
+ def load_config(filepath)
116
+ YAML::load_file(filepath)
117
+ end
118
+
119
+ # Store the Hash object as a Yaml file
120
+ def store_config(filepath, hash)
121
+ File.open( filepath, 'w') do |f|
122
+ f.print "# ", File.basename(filepath), "\n"
123
+ f.puts "# /!\\ DO NOT EDIT THIS FILE: it has been automatically generated"
124
+ f.puts hash.to_yaml
125
+ end
126
+ end
127
+
128
+
129
+ end
130
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'falkorlib/common'
4
+ require 'git'
5
+
6
+ module FalkorLib
7
+
8
+ class GitFlow < Git::Base
9
+
10
+ @@config = {
11
+ :master => 'production',
12
+ :develop => 'master',
13
+ :feature => 'feature/',
14
+ :release => 'release/',
15
+ :hotfix => 'hotfix/',
16
+ :support => 'support/',
17
+ :versiontag => "v",
18
+ }
19
+
20
+
21
+ def initialize(base = nil, options = {})
22
+ # @logger = options[:logger] || Logger.new(STDOUT)
23
+ options.each do |k,v|
24
+ self.config_set(k, v) if @@config.has_key?(k.to_sym)
25
+ end
26
+ #puts @@config.inspect
27
+ end
28
+
29
+ # def self.method_missing(sym, *args, &block)
30
+ # @@config[sym.to_s]
31
+ # end
32
+
33
+ def self.global_config(opt)
34
+ @@config[opt.to_sym]
35
+ end
36
+
37
+ def self.config_set(opt, value)
38
+ @@config[opt.to_sym] = value
39
+ end
40
+
41
+ # initializes a git flow repository
42
+ # options:
43
+ # :repository
44
+ # :index_file
45
+ #
46
+ def self.init(working_dir, opts = {})
47
+ super
48
+ g = Git.open(working_dir)
49
+
50
+ config = @@config
51
+ @@config.keys.each do |k|
52
+ config[k.to_sym] = opts[k.to_sym] if opts.has_key?(k.to_sym)
53
+ end
54
+
55
+ # Now update the local config for gitflow
56
+ g.config('gitflow.branch.master', config[:master])
57
+ g.config('gitflow.branch.develop', config[:develop])
58
+ g.config('gitflow.prefix.feature', config[:feature])
59
+ g.config('gitflow.prefix.release', config[:release])
60
+ g.config('gitflow.prefix.hotfix', config[:hotfix])
61
+ g.config('gitflow.prefix.support', config[:support])
62
+ g.config('gitflow.prefix.versiontag', config[:versiontag])
63
+
64
+ g.lib.send('command', 'flow init -d')
65
+ end
66
+
67
+
68
+
69
+
70
+ end # End Falkorlib::GitFlow
71
+ end