minarai 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.rubocop.yml +41 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +6 -0
- data/bin/minarai +5 -0
- data/examples/recipe_directory.yml +8 -0
- data/examples/recipe_erb.yml.erb +13 -0
- data/examples/recipe_file.yml +11 -0
- data/examples/recipe_git.yml +9 -0
- data/examples/recipe_homebrew.yml +6 -0
- data/examples/recipe_homebrew_cask.yml +6 -0
- data/examples/recipe_link.yml +4 -0
- data/examples/recipe_url_get.yml +4 -0
- data/examples/recipe_variable.yml +4 -0
- data/lib/minarai.rb +6 -0
- data/lib/minarai/action_builder.rb +47 -0
- data/lib/minarai/actions/base.rb +87 -0
- data/lib/minarai/actions/directory.rb +51 -0
- data/lib/minarai/actions/file.rb +85 -0
- data/lib/minarai/actions/git.rb +36 -0
- data/lib/minarai/actions/homebrew.rb +35 -0
- data/lib/minarai/actions/homebrew_cask.rb +35 -0
- data/lib/minarai/actions/link.rb +53 -0
- data/lib/minarai/actions/unknown.rb +26 -0
- data/lib/minarai/actions/url_get.rb +38 -0
- data/lib/minarai/command.rb +47 -0
- data/lib/minarai/errors/attribute_validation_error.rb +17 -0
- data/lib/minarai/errors/base.rb +6 -0
- data/lib/minarai/errors/invalid_action_type_error.rb +15 -0
- data/lib/minarai/errors/missing_recipe_path_error.rb +11 -0
- data/lib/minarai/loaders/base.rb +75 -0
- data/lib/minarai/loaders/recipe_loader.rb +39 -0
- data/lib/minarai/loaders/variable_loader.rb +14 -0
- data/lib/minarai/logger.rb +69 -0
- data/lib/minarai/recipe.rb +28 -0
- data/lib/minarai/runner.rb +22 -0
- data/lib/minarai/variable.rb +19 -0
- data/lib/minarai/version.rb +3 -0
- data/lib/validator/required_validator.rb +7 -0
- data/lib/validator/type_validator.rb +13 -0
- data/minarai.gemspec +30 -0
- data/spec/minarai/unit/action/base_spec.rb +26 -0
- data/spec/minarai/unit/action_builder_spec.rb +21 -0
- data/spec/minarai/unit/logger_spec.rb +18 -0
- data/spec/minarai/unit/variable_spec.rb +11 -0
- data/spec/spec_helper.rb +5 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 331d77505539cdeadc19788264bf3bc739a4dd4c
|
4
|
+
data.tar.gz: fd0be076dc26505e0b9bbb1481914cc7a1f0091a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 920fa98a7399113be93930e93b4a5f91cbbef3a1598193e9e83d1de16a4a34a5c0f9ff9e438b3664cbee14fc550d3067ffc202d06b9ecb3e400b01cfbf38a25c
|
7
|
+
data.tar.gz: 9214cf2fe72770f647a946d07075822ce72c246ca159d41411aead0e2090491ae7100383c5cf711ecc46c595b3b9ed54a57ea99d0857376e026d12b7ee0496d0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 120
|
3
|
+
|
4
|
+
Metrics/CyclomaticComplexity:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/ClassLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 40
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
CountComments: false
|
15
|
+
Max: 19
|
16
|
+
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/AsciiComments:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/SignalException:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/DoubleNegation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/GuardClause:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/AndOr:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/FormatString:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/PredicateName:
|
39
|
+
NamePrefixBlacklist:
|
40
|
+
- is_
|
41
|
+
- have_
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 ganmacs
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Minarai
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
$ gem install minarai
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TODO: Write usage instructions here
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it ( https://github.com/[my-github-username]/minarai/fork )
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/minarai
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
- name: install vim
|
2
|
+
type: homebrew
|
3
|
+
item: vim
|
4
|
+
|
5
|
+
- name: clone dotfile
|
6
|
+
type: git
|
7
|
+
repository: <%= remote_dotfile_repo %>
|
8
|
+
destination: <%= dotfile_path %>
|
9
|
+
|
10
|
+
- name: link dotfile to hgoe
|
11
|
+
type: link
|
12
|
+
source: <%= vim_config_in_dotfile %>
|
13
|
+
destination: <%= dot_vim_path %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
- name: copy recipe to recipe3
|
2
|
+
type: file
|
3
|
+
source: ./examples/recipe_file.yml
|
4
|
+
destination: ./examples/recipe_file3.yml
|
5
|
+
|
6
|
+
- name: copy recipe to recipe4
|
7
|
+
type: file
|
8
|
+
group: staff
|
9
|
+
owner: ganmacs
|
10
|
+
source: ./examples/recipe_file.yml
|
11
|
+
destination: ./examples/recipe_file4.yml
|
data/lib/minarai.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
require 'minarai/actions/git'
|
3
|
+
require 'minarai/actions/file'
|
4
|
+
require 'minarai/actions/homebrew'
|
5
|
+
require 'minarai/actions/homebrew_cask'
|
6
|
+
require 'minarai/actions/link'
|
7
|
+
require 'minarai/actions/unknown'
|
8
|
+
require 'minarai/actions/directory'
|
9
|
+
require 'minarai/actions/url_get'
|
10
|
+
|
11
|
+
module Minarai
|
12
|
+
class ActionBuilder
|
13
|
+
def initialize(attirbutes)
|
14
|
+
@attirbutes = attirbutes
|
15
|
+
end
|
16
|
+
|
17
|
+
def build
|
18
|
+
action_class.new(@attirbutes)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def action_class
|
24
|
+
if known_action_type?
|
25
|
+
Minarai::Actions.const_get(action_class_name, false)
|
26
|
+
else
|
27
|
+
Minarai::Actions::Unknown
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def known_action_type?
|
32
|
+
has_type? && Minarai::Actions.constants.include?(action_class_name.to_sym)
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_class_name
|
36
|
+
type.camelize
|
37
|
+
end
|
38
|
+
|
39
|
+
def type
|
40
|
+
@attirbutes['type']
|
41
|
+
end
|
42
|
+
|
43
|
+
def has_type?
|
44
|
+
!!@attirbutes['type']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'validator/required_validator'
|
3
|
+
require 'validator/type_validator'
|
4
|
+
require 'minarai/errors/attribute_validation_error'
|
5
|
+
require 'minarai/logger'
|
6
|
+
|
7
|
+
module Minarai
|
8
|
+
module Actions
|
9
|
+
class Base
|
10
|
+
class << self
|
11
|
+
def attribute(name, options = {})
|
12
|
+
default = options.delete(:default)
|
13
|
+
define_method(name) do
|
14
|
+
@attributes[name.to_s] || default
|
15
|
+
end
|
16
|
+
validates name, options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
include ActiveModel::Validations
|
21
|
+
|
22
|
+
attr_accessor :backend
|
23
|
+
|
24
|
+
def initialize(attributes)
|
25
|
+
@attributes = attributes
|
26
|
+
end
|
27
|
+
|
28
|
+
def call
|
29
|
+
if complete?
|
30
|
+
Minarai::Logger.skip "[SKIP] #{name}"
|
31
|
+
else
|
32
|
+
run
|
33
|
+
if complete?
|
34
|
+
Minarai::Logger.done "[DONE] #{name}"
|
35
|
+
else
|
36
|
+
Minarai::Logger.fail "[FAIL] #{name}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
raise NotImplementedError
|
43
|
+
end
|
44
|
+
|
45
|
+
def error_messages
|
46
|
+
validation_error_messages
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def complete?
|
52
|
+
raise NotImplementedError
|
53
|
+
end
|
54
|
+
|
55
|
+
def validated?
|
56
|
+
validate
|
57
|
+
end
|
58
|
+
|
59
|
+
def validation_error_messages
|
60
|
+
validate
|
61
|
+
errors.map do |attribute, error_message|
|
62
|
+
Minarai::Errors::AttributeValidationError.new(attribute, error_message, name)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def name
|
67
|
+
@attributes['name']
|
68
|
+
end
|
69
|
+
|
70
|
+
def run_command(*args)
|
71
|
+
backend.run_command(*args)
|
72
|
+
end
|
73
|
+
|
74
|
+
def check_command(*args)
|
75
|
+
run_command(*args).success?
|
76
|
+
end
|
77
|
+
|
78
|
+
def run_specific_command(method, *args)
|
79
|
+
run_command(backend.command.get(method, *args))
|
80
|
+
end
|
81
|
+
|
82
|
+
def check_specific_command(method, *args)
|
83
|
+
run_specific_command(method, *args).success?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'minarai/actions/base'
|
2
|
+
|
3
|
+
module Minarai
|
4
|
+
module Actions
|
5
|
+
class Directory < Base
|
6
|
+
attribute :destination, required: true, type: String
|
7
|
+
attribute :owner, type: String
|
8
|
+
attribute :group, type: String
|
9
|
+
|
10
|
+
def run
|
11
|
+
create
|
12
|
+
change_group unless has_valid_group?
|
13
|
+
change_owner unless has_valid_owner?
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create
|
19
|
+
run_specific_command(:create_file_as_directory, destination)
|
20
|
+
end
|
21
|
+
|
22
|
+
def complete?
|
23
|
+
existed_file?
|
24
|
+
end
|
25
|
+
|
26
|
+
def existed_file?
|
27
|
+
check_specific_command(:check_file_is_directory, destination)
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_valid_group?
|
31
|
+
group.nil? || check_specific_command(:check_file_is_grouped, destination, group)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_valid_owner?
|
35
|
+
owner.nil? || check_specific_command(:check_file_is_owned_by, destination, owner)
|
36
|
+
end
|
37
|
+
|
38
|
+
def change_group
|
39
|
+
run_specific_command(:change_file_group, destination, group)
|
40
|
+
end
|
41
|
+
|
42
|
+
def change_owner
|
43
|
+
run_specific_command(:change_file_owner, destination, owner)
|
44
|
+
end
|
45
|
+
|
46
|
+
def name
|
47
|
+
super || "create #{destination} directory"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'minarai/actions/base'
|
2
|
+
|
3
|
+
module Minarai
|
4
|
+
module Actions
|
5
|
+
class File < Base
|
6
|
+
attribute :destination, required: true, type: String
|
7
|
+
attribute :source, required: true, type: String
|
8
|
+
attribute :owner, type: String
|
9
|
+
attribute :group, type: String
|
10
|
+
|
11
|
+
def call
|
12
|
+
abort_with_runtime_error unless runnable?
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
copy
|
18
|
+
change_group unless has_valid_group?
|
19
|
+
change_owner unless has_valid_owner?
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def copy
|
25
|
+
run_specific_command(:copy_file, source, destination)
|
26
|
+
end
|
27
|
+
|
28
|
+
def runnable?
|
29
|
+
readable_source?
|
30
|
+
end
|
31
|
+
|
32
|
+
def abort_with_runtime_error
|
33
|
+
Minarai::Logger.errorr(runtime_error) and abort
|
34
|
+
end
|
35
|
+
|
36
|
+
def runtime_error
|
37
|
+
Minarai::Errors::AttributeValidationError.new('source', 'is not readable file', name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def complete?
|
41
|
+
existed_file? && same_content?
|
42
|
+
end
|
43
|
+
|
44
|
+
def raeadable_source?
|
45
|
+
!source.nil? && ::File.readable?(source)
|
46
|
+
end
|
47
|
+
|
48
|
+
def existed_file?
|
49
|
+
check_specific_command(:check_file_is_file, destination)
|
50
|
+
end
|
51
|
+
|
52
|
+
def same_content?
|
53
|
+
sha256_content(destination) == sha256_content(source)
|
54
|
+
end
|
55
|
+
|
56
|
+
def sha256_content(path)
|
57
|
+
run_specific_command(:get_file_sha256sum, path).stdout.rstrip
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_valid_group?
|
61
|
+
group.nil? || check_specific_command(:check_file_is_grouped, destination, group)
|
62
|
+
end
|
63
|
+
|
64
|
+
def has_valid_owner?
|
65
|
+
owner.nil? || check_specific_command(:check_file_is_owned_by, destination, owner)
|
66
|
+
end
|
67
|
+
|
68
|
+
def change_group
|
69
|
+
run_specific_command(:change_file_group, destination, group)
|
70
|
+
end
|
71
|
+
|
72
|
+
def change_owner
|
73
|
+
run_specific_command(:change_file_owner, destination, owner)
|
74
|
+
end
|
75
|
+
|
76
|
+
def has_source?
|
77
|
+
!source.nil?
|
78
|
+
end
|
79
|
+
|
80
|
+
def name
|
81
|
+
super || "copy #{repository} to #{destination}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|