cachivache 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ # Example:
2
+ #
3
+ # configure Something do
4
+ # let(:bla) { '123' }
5
+ # let(:ble) { 'abc' }
6
+ # end
7
+ def configure(klass, &block)
8
+ klass.instance_eval(&block)
9
+ end
10
+
11
+ module Stuff
12
+ class Configuration
13
+ # Class methods
14
+ class << self
15
+ def variables()
16
+ @variables ||= {}
17
+ end
18
+
19
+ def has_variable?(name)
20
+ variables.key?(name)
21
+ end
22
+
23
+ def is_defined?(name)
24
+ has_variable?(name) && !variables[name].nil?
25
+ end
26
+
27
+ def let(name, &block)
28
+ variables[name] = block
29
+ end
30
+
31
+ def [](name)
32
+ raise "Can't find variable named #{name.inspect}" unless has_variable?(name)
33
+ variables[name].call
34
+ end
35
+
36
+ def creating_undefined_subclasses(&block)
37
+ begin
38
+ block.call
39
+ rescue NameError => e
40
+ raise e unless is_class_name e.name
41
+
42
+ define_subclass(e.name)
43
+ retry
44
+ end
45
+ end
46
+
47
+ protected
48
+
49
+ def method_missing(name, *more_args, &block)
50
+ return self[name] if more_args.empty? && block.nil?
51
+
52
+ super(name, *more_args, &block)
53
+ end
54
+
55
+ def is_class_name(const)
56
+ const[0] == const[0].upcase
57
+ end
58
+
59
+ def define_subclass(name)
60
+ Object.const_set(name, Class.new(self))
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ module Stuff
2
+ module RemindersBehaviour
3
+ def reminders()
4
+ @reminders ||= []
5
+ end
6
+
7
+ def show_reminders()
8
+ reminders.each { |alert| show_info(alert) }
9
+ end
10
+
11
+ def show_info(text)
12
+ puts '-----------------------------------------------'.red
13
+ puts text.green
14
+ puts '-----------------------------------------------'.red
15
+ end
16
+ end
17
+ end
File without changes
@@ -0,0 +1,42 @@
1
+ ############################################
2
+ # This is an example of a stuff file for your project.
3
+ # You can have as many stuffs and projects as you want, just let cachivache know that
4
+ # it has to install them by editing the cachivache.rb file and fill the section:
5
+ #
6
+ # let(:stuff_to_install) {
7
+ # [
8
+ # 'php-json-spec',
9
+ # ]
10
+ # }
11
+ #
12
+ ############################################
13
+
14
+ # Declare the dependencies of this project
15
+ dependencies = [
16
+ :'projects-setup',
17
+ :graphviz,
18
+ :xdebug,
19
+ :'php-cli',
20
+ :composer,
21
+ ]
22
+
23
+ # Define the main task of this project
24
+ stuff :'php-json-spec' => dependencies do
25
+ shell %{
26
+ cd #{StuffSample.project_folder}
27
+
28
+ composer install
29
+
30
+ # Run the test coverage report
31
+ php vendor/bin/phpunit -c phpunit-with-coverage.xml
32
+
33
+ # Generate the documentation
34
+ php vendor/bin/phpdoc
35
+ }
36
+
37
+ remind_to "You can check the reports in the #{StuffSample.project_folder}/ouput folder"
38
+ end
39
+
40
+ configure StuffSample do
41
+ let(:project_folder) { Cachivache.src_folder }
42
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cachivache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cachivache"
8
+ spec.version = Cachivache::VERSION
9
+ spec.authors = ["Martin Rubi"]
10
+ spec.email = ["martinrubi@gmail.com"]
11
+
12
+ spec.summary = %q{A simple provisioner for Vagrant using bash + rake.}
13
+ spec.description = %q{A simple provisioner for Vagrant using bash + rake.}
14
+ spec.homepage = "https://github.com/cabeza-de-termo/cachivache"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables << 'cachivache'
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor", '~> 0'
23
+ spec.add_dependency "colorize", '~> 0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.8"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
data/lib/cachivache.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'thor'
2
+ require 'colorize'
3
+
4
+ require_relative "cachivache/version"
5
+ require_relative "cachivache/command"
6
+ require_relative "cachivache/init-command"
7
+ require_relative "cachivache/configure-command"
8
+ require_relative "cachivache/add-stuff-libraries-command"
9
+ require_relative "cachivache/update-stuff-libraries-command"
10
+ require_relative "cachivache/remove-stuff-libraries-command"
11
+
12
+ module Cachivache
13
+ class CachivacheCLI < Thor
14
+ desc "init", "Initializes a Cachivache Vagrant configuration for your project."
15
+ def init()
16
+ InitCommand.run
17
+ end
18
+
19
+ desc "configure", "Opens an editor to configure cachivache."
20
+ def configure()
21
+ ConfigureCommand.run
22
+ end
23
+
24
+ desc "add-stuff-library GIT-REPO", "Adds a stuff library from a git repository."
25
+ def add_stuff_library(library_repo)
26
+ AddStuffLibrariesCommand.run(library_repo)
27
+ end
28
+
29
+ desc "update-stuff-libraries [STUFF-NAME-1 STUFF-NAME-2 ...]", "Updates some or all of the added stuff libraries."
30
+ def update_stuff_libraries(*libraries)
31
+ UpdateStuffLibrariesCommand.run(libraries)
32
+ end
33
+
34
+ desc "remove-stuff-libraries STUFF-NAME-1 STUFF-NAME-2 ...", "Removes the stuff libraries."
35
+ def remove_stuff_libraries(*libraries)
36
+ RemoveStuffLibrariesCommand.run(libraries)
37
+ end
38
+ end
39
+ end
40
+
41
+ Cachivache::CachivacheCLI.start(ARGV)
@@ -0,0 +1,12 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Cachivache
5
+ class AddStuffLibrariesCommand < Command
6
+ def run(library_repo)
7
+ validate_cachivache_folder
8
+
9
+ system "git submodule add --force #{library_repo}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ module Cachivache
2
+ class Command
3
+ def self.run(*args, &block)
4
+ self.new.run(*args, &block)
5
+ end
6
+
7
+ def run(*args, &block)
8
+ raise 'Subclass responsibility'
9
+ end
10
+
11
+ def current_folder()
12
+ Pathname('.')
13
+ end
14
+
15
+ def gem_folder()
16
+ Pathname( File.dirname(__FILE__) ) + '../../bin'
17
+ end
18
+
19
+ def validate_cachivache_folder()
20
+ raise_error "Can't find a 'cachivache.rb' file in this folder." unless File.exist? current_folder + 'cachivache.rb'
21
+ end
22
+
23
+ def raise_error(message)
24
+ puts message.red
25
+ exit
26
+ end
27
+
28
+ def inform(message)
29
+ puts message.green
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Cachivache
5
+ class ConfigureCommand < Command
6
+ def run()
7
+ validate_cachivache_folder
8
+ system 'pico cachivache.rb'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Cachivache
5
+ class InitCommand < Command
6
+ def run()
7
+ copy_template_folder
8
+ clone_stuff_library_submodule
9
+
10
+ inform "A 'cachivache' folder with a Vagrant configuration was created."
11
+ end
12
+
13
+ def template_folder()
14
+ gem_folder + 'template'
15
+ end
16
+
17
+ def destination()
18
+ current_folder + 'cachivache'
19
+ end
20
+
21
+ def copy_template_folder()
22
+ raise_folder_exist_error if File.directory? destination
23
+
24
+ FileUtils.mkdir destination
25
+ FileUtils.copy_entry template_folder, destination
26
+ end
27
+
28
+ def clone_stuff_library_submodule()
29
+ system "git submodule add #{stuff_library_repo} cachivache/stuff-library"
30
+ end
31
+
32
+ def stuff_library_repo()
33
+ 'https://github.com/cabeza-de-termo/stuff-library'
34
+ end
35
+
36
+ def raise_folder_exist_error()
37
+ raise_error "A folder 'cachivache' already exists."
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Cachivache
5
+ class RemoveStuffLibrariesCommand < Command
6
+ def run(libraries)
7
+ validate_cachivache_folder
8
+ raise_error 'You must give a library' if libraries.empty?
9
+
10
+ libraries.each { |library| remove_library library }
11
+ end
12
+
13
+ def remove_library(library)
14
+ system "git submodule deinit --force #{library}"
15
+ system "git rm --force #{library}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module Cachivache
5
+ class UpdateStuffLibrariesCommand < Command
6
+ def run(libraries)
7
+ validate_cachivache_folder
8
+
9
+ libraries << default_libraries if libraries.empty?
10
+ system "git submodule update --remote #{ libraries.join(' ') }"
11
+ end
12
+
13
+ def default_libraries
14
+ '.'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Cachivache
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cachivache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Rubi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: A simple provisioner for Vagrant using bash + rake.
70
+ email:
71
+ - martinrubi@gmail.com
72
+ executables:
73
+ - cachivache
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/cachivache
83
+ - bin/setup
84
+ - bin/template/.gitignore
85
+ - bin/template/Gemfile
86
+ - bin/template/README.md
87
+ - bin/template/Rakefile
88
+ - bin/template/Vagrantfile
89
+ - bin/template/cachivache.rb
90
+ - bin/template/lib/rake-helper.rb
91
+ - bin/template/lib/shell-contexts/shell-context.rb
92
+ - bin/template/lib/shell-contexts/shell-exec.rb
93
+ - bin/template/lib/shell-contexts/shell_buffer.rb
94
+ - bin/template/lib/shell-file-context.rb
95
+ - bin/template/lib/shell-if-context.rb
96
+ - bin/template/lib/stuff-api-behaviour.rb
97
+ - bin/template/lib/stuff-configuration.rb
98
+ - bin/template/lib/stuff-reminders-behaviour.rb
99
+ - bin/template/stuff/.gitkeep
100
+ - bin/template/stuff/stuff_sample.rb
101
+ - cachivache.gemspec
102
+ - lib/cachivache.rb
103
+ - lib/cachivache/add-stuff-libraries-command.rb
104
+ - lib/cachivache/command.rb
105
+ - lib/cachivache/configure-command.rb
106
+ - lib/cachivache/init-command.rb
107
+ - lib/cachivache/remove-stuff-libraries-command.rb
108
+ - lib/cachivache/update-stuff-libraries-command.rb
109
+ - lib/cachivache/version.rb
110
+ homepage: https://github.com/cabeza-de-termo/cachivache
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: A simple provisioner for Vagrant using bash + rake.
134
+ test_files: []