rares 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +162 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rares +14 -0
- data/bin/setup +8 -0
- data/lib/rares.rb +7 -0
- data/lib/rares/command.rb +55 -0
- data/lib/rares/exceptions/exit.rb +6 -0
- data/lib/rares/main.rb +45 -0
- data/lib/rares/modules/input.rb +24 -0
- data/lib/rares/modules/shell.rb +37 -0
- data/lib/rares/modules/text_file.rb +111 -0
- data/lib/rares/version.rb +3 -0
- data/rares.gemspec +43 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d83eb80b8a34d0d11c86a9c335b51d3a7e80a6db9a26ea609b6d274a0dc21158
|
4
|
+
data.tar.gz: e992448eb444cf085ddc1bd7c9df8832eda53faf13e79d578371a414c0f57225
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 144206a14f1cf64cea4c32c1d05341c18ee7b726fb26b058c3be5de44aaa3ba600041b2efa2c4e0ddce0cce9ff978b371711b47cce0ed8c0fbbda908076f8c55
|
7
|
+
data.tar.gz: 9f5169f688f8af41b8bce08304b976d68981c03e1170e52f1ac7493037b3f502e247b8aa9b7c3fdac4b0096b9df0958f290670904e449d92d61a1992c21c8195
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
First version
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at olegz@jetruby.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rares (0.1.4)
|
5
|
+
rubyzip
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.8.0)
|
13
|
+
rspec-core (~> 3.8.0)
|
14
|
+
rspec-expectations (~> 3.8.0)
|
15
|
+
rspec-mocks (~> 3.8.0)
|
16
|
+
rspec-core (3.8.1)
|
17
|
+
rspec-support (~> 3.8.0)
|
18
|
+
rspec-expectations (3.8.4)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-mocks (3.8.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-support (3.8.2)
|
25
|
+
rubyzip (1.2.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
rake (~> 10.0)
|
33
|
+
rares!
|
34
|
+
rspec (~> 3.0)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Oleg Zaporozhchenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
# Rares
|
2
|
+
|
3
|
+
Rares is a client for the RampageRecipes server.
|
4
|
+
|
5
|
+
Currently each mainstream programming language has its own package manager. And developers can create an unique solutions and wrap them to packages, libraries, gems, whatever.
|
6
|
+
|
7
|
+
Usually this is a small solution which can be configured for solving some unique issues. And usually those libraries solve some technical issues: compress image, integration with any search engine, some third-party API clients and so on.
|
8
|
+
|
9
|
+
However it's kind of rare case when package contains a business logic. This is because each business case are unique and it's imposible to write some unique solution. It will have a lot of configurations. Its code will be to complex. It will have a lot of redundant code.
|
10
|
+
|
11
|
+
So, what is a RampageRecipe. Just imagine, that you have a good written article about how to solve you issue and you can intall this solution from article in few clicks. This is what recipes do.
|
12
|
+
|
13
|
+
Recipes are written in specific format, which allows you update and add it to you code in few minutes. The RampageRecipes server provides you a web interface for rapid recipes editing.
|
14
|
+
|
15
|
+
### Pros:
|
16
|
+
1. Comparing to other configurators you will see what exactly the recipe will change.
|
17
|
+
2. You can modify recipe in few clicks and append it to your own needs
|
18
|
+
### Cons:
|
19
|
+
1. Because of using eval you need to check the code written by other person
|
20
|
+
|
21
|
+
Please visit an [official repository](http://rampagerecipes.com) to find some usefull recipes.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
$ gem install rares
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Download and apply recipe from [official repository](http://rampagerecipes.com)
|
30
|
+
|
31
|
+
$ rares -r <unique_hash>
|
32
|
+
|
33
|
+
Download and apply recipe from your own repository
|
34
|
+
|
35
|
+
$ rares -r <unique_hash> -s http://youdomain.com
|
36
|
+
|
37
|
+
Apply recipe from local folder
|
38
|
+
|
39
|
+
$ rares -l /home/user/recipes/install_rails
|
40
|
+
|
41
|
+
## Writing recipes
|
42
|
+
|
43
|
+
* recipe root/
|
44
|
+
* doc/
|
45
|
+
* 01_install_rails.md
|
46
|
+
* 02_install_new_gems.md
|
47
|
+
* fixtures/
|
48
|
+
* any_folder/
|
49
|
+
* file0.txt
|
50
|
+
* file1.txt
|
51
|
+
* recipe/
|
52
|
+
* 01_install_rails.rb
|
53
|
+
* 02_install_new_gems.rb
|
54
|
+
|
55
|
+
The `recipe` folder contains the performed steps. It's recommended to split your recipe to some logical steps, because users will be able to turn on/off them on frontend.
|
56
|
+
|
57
|
+
The `doc` folder should have documents for each recipe file with the same name as files from the recipe folder. Should use the markdown language
|
58
|
+
|
59
|
+
The `fixtures` folder contains files wich will be copied as is
|
60
|
+
|
61
|
+
## Recipe DSL
|
62
|
+
|
63
|
+
### Check git status
|
64
|
+
|
65
|
+
It's usefull to have commited changes before running the recipe. You can force it with the next command:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
ensure_changes_commited!
|
69
|
+
```
|
70
|
+
### Working with shell
|
71
|
+
|
72
|
+
You can ask user to enter any data:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
ruby_version = ask("Please enter the desired ruby version")
|
76
|
+
pust "ok" if yes?("You sure")
|
77
|
+
pust "ok" unless no?("You sure")
|
78
|
+
```
|
79
|
+
|
80
|
+
You can run any shell command
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
result = run "echo 'hello' > hello_world.txt"
|
84
|
+
```
|
85
|
+
|
86
|
+
Also you can copy the fixture file. It will create the same file and reproduce the fixture path in current directory
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
copy_fixture "config/locales/ch.yml"
|
90
|
+
```
|
91
|
+
|
92
|
+
### Patching existing file or creatind a new one.
|
93
|
+
|
94
|
+
First you should define which file you want to change with
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
file 'routes.rb' do
|
98
|
+
# do some things
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
Then inside file block you can manipulate with file. The first argument is alway an inserted content. The second one is a line matcher, which can be string or regext. Please note that the line matcher should match only a single line.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
file 'routes.rb' do
|
106
|
+
api = <<~API
|
107
|
+
namespace :api do
|
108
|
+
namespace :v1 do
|
109
|
+
resources :users
|
110
|
+
end
|
111
|
+
end
|
112
|
+
API
|
113
|
+
|
114
|
+
beginning = <<~BEG
|
115
|
+
# this is the router file
|
116
|
+
BEG
|
117
|
+
|
118
|
+
put_to_beginning beginning
|
119
|
+
put_to_end "puts Dir.pwd"
|
120
|
+
|
121
|
+
replace_line "root 'welcome'", /root/
|
122
|
+
|
123
|
+
indent 2 do
|
124
|
+
put_after_line "resources :users", "draw do"
|
125
|
+
end
|
126
|
+
|
127
|
+
put_before_line api, "root"
|
128
|
+
end
|
129
|
+
|
130
|
+
file 'package.json' do
|
131
|
+
indent 2 do
|
132
|
+
put_after_line "\"second\",", "angular", 1
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
file '.ruby-version' do
|
137
|
+
clean_file!
|
138
|
+
put_to_beginning "2.5.3"
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
Each method also can receive the offset. But try to avoid this. Example below will show how to add new line before the last_ ne.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
file 'test.txt' do
|
146
|
+
put_to_end "Hello", -1
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
## Contributing
|
153
|
+
|
154
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/c3gdlk/rares. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
155
|
+
|
156
|
+
## License
|
157
|
+
|
158
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
159
|
+
|
160
|
+
## Code of Conduct
|
161
|
+
|
162
|
+
Everyone interacting in the Rares project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/c3gdlk/rares/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rares"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rares
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rares"
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
opt_parser = OptionParser.new do |opt|
|
8
|
+
opt.banner = "Welcome to rares."
|
9
|
+
opt.on("-s", "--remote-host=HOST", "The recipes server. http://rampagerecipes.com by default") { |remote_host| options[:remote_host] = remote_host }
|
10
|
+
opt.on("-r", "--remote-id=ID", "Recipe ID generated by recipes server") { |remote_id| options[:remote_id] = remote_id }
|
11
|
+
opt.on("-l", "--local-folder=PATH", "Allow to run local recipe") { |local_path| options[:local_path] = local_path }
|
12
|
+
end.parse!
|
13
|
+
|
14
|
+
Rares::Command.new(options).run
|
data/bin/setup
ADDED
data/lib/rares.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'zip'
|
3
|
+
|
4
|
+
module Rares
|
5
|
+
class Command
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
DEFAULT_HOST = 'http://rampagerecipes.com'
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
if options[:remote_id]
|
16
|
+
id = options[:remote_id]
|
17
|
+
directory = File.join Dir.pwd, "tmp", "rares", id
|
18
|
+
FileUtils.rm_rf File.join Dir.pwd, "tmp", "rares"
|
19
|
+
FileUtils.mkdir_p(directory)
|
20
|
+
|
21
|
+
download_and_extract_recipe!(options[:remote_host] || DEFAULT_HOST, id, directory)
|
22
|
+
|
23
|
+
Rares::Main.new(directory, Dir.pwd).perform
|
24
|
+
elsif options[:local_path]
|
25
|
+
puts "Using local folder #{options[:local_path]}"
|
26
|
+
Rares::Main.new(options[:local_path], Dir.pwd).perform
|
27
|
+
else
|
28
|
+
puts "Should provide remote id or local path"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def download_and_extract_recipe!(host, id, directory)
|
35
|
+
file_url = "#{host}/files/#{id}.zip"
|
36
|
+
puts "Fetching #{file_url}"
|
37
|
+
|
38
|
+
begin
|
39
|
+
content = open(file_url)
|
40
|
+
rescue Exception
|
41
|
+
puts "Could not nownload the file"
|
42
|
+
puts "1. File can be missing on server. Go to the web interface and create a new version"
|
43
|
+
puts "2. You may try to upgrade the client. Run `gem update`"
|
44
|
+
puts "3. Check your network connection"
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
::Zip::File.open_buffer(content) do |zip|
|
49
|
+
zip.each do |entry|
|
50
|
+
entry.extract(File.join(directory, entry.name))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rares/main.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative 'modules/text_file'
|
4
|
+
require_relative 'modules/input'
|
5
|
+
require_relative 'modules/shell'
|
6
|
+
|
7
|
+
require_relative 'exceptions/exit'
|
8
|
+
|
9
|
+
module Rares
|
10
|
+
class Main
|
11
|
+
include Rares::Modules::TextFile
|
12
|
+
include Rares::Modules::Input
|
13
|
+
include Rares::Modules::Shell
|
14
|
+
|
15
|
+
attr_reader :recipe_folder, :current_dir, :current_file_path, :current_file_content, :current_indent
|
16
|
+
|
17
|
+
def initialize(recipe_folder, project_dir)
|
18
|
+
@recipe_folder = recipe_folder
|
19
|
+
@current_dir = project_dir
|
20
|
+
@current_file = nil
|
21
|
+
@current_indent = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform
|
25
|
+
files = Dir["#{recipe_folder}/recipe/**/*.rb"].sort
|
26
|
+
|
27
|
+
puts "Could not found any recipe file" if files.size == 0
|
28
|
+
files.each do |path|
|
29
|
+
puts "Processing step: #{path}"
|
30
|
+
|
31
|
+
begin
|
32
|
+
eval_file(path)
|
33
|
+
rescue Rares::Exceptions::Exit => e
|
34
|
+
puts "Exiting... Reason: #{e.message}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def eval_file(path)
|
42
|
+
eval File.new(path).read
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rares
|
2
|
+
module Modules
|
3
|
+
module Input
|
4
|
+
def ask(message)
|
5
|
+
puts message
|
6
|
+
gets.strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def yes?(message)
|
10
|
+
loop do
|
11
|
+
answer = ask("#{message} [yn]").downcase
|
12
|
+
next if answer.size == 0
|
13
|
+
return true if answer.include?('y')
|
14
|
+
return false if answer.include?('n')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def no?(message)
|
20
|
+
!yes?(message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rares
|
2
|
+
module Modules
|
3
|
+
module Shell
|
4
|
+
def ensure_changes_commited!
|
5
|
+
unless `git status`.include?("nothing to commit")
|
6
|
+
raise Rares::Exceptions::Exit, "Commit your changes first"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_fixture(file_path, options={})
|
11
|
+
fixture_path = "#{recipe_folder}/fixtures/#{file_path}"
|
12
|
+
result_path = "#{current_dir}/#{file_path}"
|
13
|
+
|
14
|
+
return if File.file?(result_path) && !(options[:force] == true) && no?("The #{result_path} already exists. Override?")
|
15
|
+
|
16
|
+
FileUtils.mkdir_p result_path.split("/")[0..-2].join("/")
|
17
|
+
|
18
|
+
if File.file?(result_path)
|
19
|
+
puts "Overrided #{file_path}"
|
20
|
+
else
|
21
|
+
puts "Created #{file_path}"
|
22
|
+
end
|
23
|
+
|
24
|
+
FileUtils.cp_r fixture_path, result_path, remove_destination: true
|
25
|
+
end
|
26
|
+
|
27
|
+
def run(command)
|
28
|
+
command_with_cd = "cd #{current_dir} && #{command}"
|
29
|
+
puts "Will execute: #{command_with_cd}"
|
30
|
+
result = `#{command_with_cd}`
|
31
|
+
puts result
|
32
|
+
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Rares
|
2
|
+
module Modules
|
3
|
+
module TextFile
|
4
|
+
def file(path, &block)
|
5
|
+
@current_file_path = "#{current_dir}/#{path}"
|
6
|
+
@current_file_content = File.file?(current_file_path) ? File.readlines(current_file_path) : []
|
7
|
+
|
8
|
+
if File.file?(@current_file_path)
|
9
|
+
puts "Will update file #{@current_file_path}"
|
10
|
+
else
|
11
|
+
puts "Will create file #{@current_file_path}"
|
12
|
+
end
|
13
|
+
|
14
|
+
yield
|
15
|
+
|
16
|
+
File.open(current_file_path, "w+") do |f|
|
17
|
+
f.puts(@current_file_content)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def indent(value)
|
22
|
+
if block_given?
|
23
|
+
current_value = @current_indent
|
24
|
+
@current_indent = value
|
25
|
+
yield
|
26
|
+
@current_indent = current_value
|
27
|
+
else
|
28
|
+
@current_indent = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def put_after_line(content, line_matcher, offset=0)
|
33
|
+
current_file_content.each_with_index do |row, ind|
|
34
|
+
if this_row?(row, line_matcher)
|
35
|
+
indent = row.count(' ') - row.lstrip.count(' ') + current_indent
|
36
|
+
add_content!(content, ind + offset + 1, indent)
|
37
|
+
return
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def put_before_line(content, line_matcher, offset=0)
|
43
|
+
current_file_content.each_with_index do |row, ind|
|
44
|
+
if this_row?(row, line_matcher)
|
45
|
+
indent = row.count(' ') - row.lstrip.count(' ') + current_indent
|
46
|
+
add_content!(content, ind + offset - 1, indent)
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def replace_line(content, line_matcher, offset=0)
|
53
|
+
current_file_content.each_with_index do |row, ind|
|
54
|
+
if this_row?(row, line_matcher)
|
55
|
+
indent = row.count(' ') - row.lstrip.count(' ')
|
56
|
+
add_content!(content, ind + offset, indent, true)
|
57
|
+
return
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def put_to_beginning(content, offset = 0)
|
63
|
+
add_content!(content, offset, 0)
|
64
|
+
end
|
65
|
+
|
66
|
+
def put_to_end(content, offset = 0)
|
67
|
+
add_content!(content, @current_file_content.size + offset, 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
def clean_file!
|
71
|
+
@current_file_content = []
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def this_row?(row, line_matcher)
|
77
|
+
(line_matcher.is_a?(String) && row.include?(line_matcher)) ||
|
78
|
+
(line_matcher.is_a?(Regexp) && line_matcher.match(row))
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_content!(content, position, indent, replace_row=false)
|
82
|
+
new_content = []
|
83
|
+
|
84
|
+
if @current_file_content.size > 0 && @current_file_content.size > position
|
85
|
+
@current_file_content.each_with_index do |row, ind|
|
86
|
+
if position == ind
|
87
|
+
content.split("\n").map { |r| ' ' * indent + r }.each do |inserted_row|
|
88
|
+
new_content << inserted_row
|
89
|
+
end
|
90
|
+
|
91
|
+
next if replace_row
|
92
|
+
end
|
93
|
+
|
94
|
+
new_content << row
|
95
|
+
end
|
96
|
+
elsif @current_file_content.size > 0 && @current_file_content.size <= position
|
97
|
+
new_content = @current_file_content
|
98
|
+
content.split("\n").map { |r| ' ' * indent + r }.each do |inserted_row|
|
99
|
+
new_content << inserted_row
|
100
|
+
end
|
101
|
+
else
|
102
|
+
content.split("\n").map { |r| ' ' * indent + r }.each do |inserted_row|
|
103
|
+
new_content << inserted_row
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
@current_file_content = new_content
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/rares.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rares/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rares"
|
8
|
+
spec.version = Rares::VERSION
|
9
|
+
spec.authors = ["Oleg Zaporozhchenko"]
|
10
|
+
spec.email = ["c3.gdlk@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{rampagerecipes.com client}
|
13
|
+
spec.description = %q{rampagerecipes.com client}
|
14
|
+
spec.homepage = "http://rampagerecipes.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/galtteam/rares"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/galtteam/rares/blob/master/CHANGELOG.md"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "bin"
|
36
|
+
spec.executables = ["rares"]
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_dependency "rubyzip"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rares
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Zaporozhchenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyzip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: rampagerecipes.com client
|
70
|
+
email:
|
71
|
+
- c3.gdlk@gmail.com
|
72
|
+
executables:
|
73
|
+
- rares
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/rares
|
89
|
+
- bin/setup
|
90
|
+
- lib/rares.rb
|
91
|
+
- lib/rares/command.rb
|
92
|
+
- lib/rares/exceptions/exit.rb
|
93
|
+
- lib/rares/main.rb
|
94
|
+
- lib/rares/modules/input.rb
|
95
|
+
- lib/rares/modules/shell.rb
|
96
|
+
- lib/rares/modules/text_file.rb
|
97
|
+
- lib/rares/version.rb
|
98
|
+
- rares.gemspec
|
99
|
+
homepage: http://rampagerecipes.com
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: http://rampagerecipes.com
|
104
|
+
source_code_uri: https://github.com/galtteam/rares
|
105
|
+
changelog_uri: https://github.com/galtteam/rares/blob/master/CHANGELOG.md
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.0.4
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: rampagerecipes.com client
|
125
|
+
test_files: []
|