minarai 0.0.1

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +41 -0
  5. data/.travis.yml +3 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +21 -0
  9. data/Rakefile +6 -0
  10. data/bin/minarai +5 -0
  11. data/examples/recipe_directory.yml +8 -0
  12. data/examples/recipe_erb.yml.erb +13 -0
  13. data/examples/recipe_file.yml +11 -0
  14. data/examples/recipe_git.yml +9 -0
  15. data/examples/recipe_homebrew.yml +6 -0
  16. data/examples/recipe_homebrew_cask.yml +6 -0
  17. data/examples/recipe_link.yml +4 -0
  18. data/examples/recipe_url_get.yml +4 -0
  19. data/examples/recipe_variable.yml +4 -0
  20. data/lib/minarai.rb +6 -0
  21. data/lib/minarai/action_builder.rb +47 -0
  22. data/lib/minarai/actions/base.rb +87 -0
  23. data/lib/minarai/actions/directory.rb +51 -0
  24. data/lib/minarai/actions/file.rb +85 -0
  25. data/lib/minarai/actions/git.rb +36 -0
  26. data/lib/minarai/actions/homebrew.rb +35 -0
  27. data/lib/minarai/actions/homebrew_cask.rb +35 -0
  28. data/lib/minarai/actions/link.rb +53 -0
  29. data/lib/minarai/actions/unknown.rb +26 -0
  30. data/lib/minarai/actions/url_get.rb +38 -0
  31. data/lib/minarai/command.rb +47 -0
  32. data/lib/minarai/errors/attribute_validation_error.rb +17 -0
  33. data/lib/minarai/errors/base.rb +6 -0
  34. data/lib/minarai/errors/invalid_action_type_error.rb +15 -0
  35. data/lib/minarai/errors/missing_recipe_path_error.rb +11 -0
  36. data/lib/minarai/loaders/base.rb +75 -0
  37. data/lib/minarai/loaders/recipe_loader.rb +39 -0
  38. data/lib/minarai/loaders/variable_loader.rb +14 -0
  39. data/lib/minarai/logger.rb +69 -0
  40. data/lib/minarai/recipe.rb +28 -0
  41. data/lib/minarai/runner.rb +22 -0
  42. data/lib/minarai/variable.rb +19 -0
  43. data/lib/minarai/version.rb +3 -0
  44. data/lib/validator/required_validator.rb +7 -0
  45. data/lib/validator/type_validator.rb +13 -0
  46. data/minarai.gemspec +30 -0
  47. data/spec/minarai/unit/action/base_spec.rb +26 -0
  48. data/spec/minarai/unit/action_builder_spec.rb +21 -0
  49. data/spec/minarai/unit/logger_spec.rb +18 -0
  50. data/spec/minarai/unit/variable_spec.rb +11 -0
  51. data/spec/spec_helper.rb +5 -0
  52. metadata +240 -0
@@ -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
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
@@ -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_
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minarai.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'minarai'
4
+
5
+ Minarai::Command.new(ARGV).call
@@ -0,0 +1,8 @@
1
+ - name: create .dir directory
2
+ type: directory
3
+ destination: ./examples/.dir
4
+
5
+ - type: directory
6
+ group: staff
7
+ owner: ganmacs
8
+ destination: ./examples/recipe_file4
@@ -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
@@ -0,0 +1,9 @@
1
+ - name: clone codic-clojure
2
+ type: git
3
+ repository: https://github.com/ganmacs/codic-clojure.git
4
+ destination: codic-clojure
5
+
6
+ - name: clone dot_emacs
7
+ type: git
8
+ repository: https://github.com/ganmacs/emacs.d.git
9
+ destination: emacs
@@ -0,0 +1,6 @@
1
+ - name: brew install peco
2
+ type: homebrew
3
+ item: peco
4
+ - name: brew install jq
5
+ type: homebrew
6
+ item: jq
@@ -0,0 +1,6 @@
1
+ - name: brew install seil
2
+ type: homebrew_cask
3
+ item: seil
4
+ - name: brew install licecap
5
+ type: homebrew_cask
6
+ item: licecap
@@ -0,0 +1,4 @@
1
+ - name: link recipe to recipe3
2
+ type: link
3
+ source: ./examples/recipe_file.yml
4
+ destination: ./examples/recipe_file3.yml
@@ -0,0 +1,4 @@
1
+ - name: get emacs to exmple/emacs
2
+ type: url_get
3
+ source: http://ftp.gnu.org/gnu/emacs/emacs-24.4.tar.gz
4
+ destination: ./examples/emacs.tar.gz
@@ -0,0 +1,4 @@
1
+ remote_dotfile_repo: git@github.com:ganmacs/dotfiles.git
2
+ dotfile_path: /Users/ganmacs/tmp/dotfile
3
+ vim_config_in_dotfile: /Users/ganmacs/tmp/dotfile/vim/vimrc
4
+ dot_vim_path: /Users/ganmacs/tmp/.vim
@@ -0,0 +1,6 @@
1
+ require 'minarai/version'
2
+ require 'minarai/command'
3
+
4
+ module Minarai
5
+ # Your code goes here...
6
+ end
@@ -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