swan 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5011d08a4d738ac351902d2d551b2651a48b63f
4
+ data.tar.gz: c805735625006e9ce7680e801209d619ccde3588
5
+ SHA512:
6
+ metadata.gz: ec83f808b986e1b4ccec8a3503bf89c0bd7e13653f64f3f530edb30ce46c69167f6e2e4fb4e97e98df47088f148dac62e79675bb4b20b5c63d902e76dadc2674
7
+ data.tar.gz: ce5ceefa2a7d06defe8448a3fbd61dbf770989926f15c9ce86e433b0f93aadb7f0b42c7dd49bc28ae62ccd07b7b058383d1703ac744ba94e315bfee9be26035c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at gilbert_90@mail.ru. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swan.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Stas Karpov
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,85 @@
1
+ # Swan
2
+
3
+ Often there are many config files that need to be shared between many projects and keeping them up to date in every project can be annoying.
4
+ Usually it is done by hands copypasting them from project to project.
5
+ Swan is a tool to help automate this process.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'swan'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install swan
22
+
23
+ ## Usage
24
+
25
+ Swan provides a command-line interface through `swan` command.
26
+
27
+ If you don't have swan config in your project yet, then run:
28
+
29
+ $ swan --init
30
+
31
+ It will create a config file, where you can specify files you want to share between projects.
32
+
33
+ Example config:
34
+
35
+ ```yaml
36
+ rubocop:
37
+ url: 'http://example.com/.rubocop.yml'
38
+ filename: '.rubocop.yml'
39
+ dir: '.'
40
+ ```
41
+
42
+ which can also be simplified to:
43
+
44
+ ```yaml
45
+ .rubocop.yml: 'http://example.com/.rubocop.yml'
46
+ ```
47
+
48
+ Root level elements are key names, which can be referenced in command line if needed.
49
+
50
+ `url` - location of the file to be downloaded. Can be local (relative or absolute) or remote.
51
+
52
+ `filename` - filename to save file to. If not specified, root name will be used.
53
+
54
+ `dir` - where to save file. Current directory by default.
55
+
56
+ ### Command line
57
+
58
+ Gem exposes command:
59
+
60
+ $ swan
61
+
62
+ This command will download and override specified files.
63
+
64
+ To download only specific files, run command with `--only comma_separated_key_names` option.
65
+
66
+ To use another config file, add `--config config.yml` or `-c config.yml` option.
67
+
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`.
74
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
75
+ which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/staskjs/swan. 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.
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
85
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "swan"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/swan ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'swan'
5
+ require 'optparse'
6
+ require 'yaml'
7
+ require 'open-uri'
8
+
9
+ options = {
10
+ init: false,
11
+ init_params: '',
12
+ only: [],
13
+ config: '.swan.yml',
14
+ }
15
+
16
+ # Parse options
17
+ OptionParser.new do |opts|
18
+ opts.banner = 'Usage: swan [options]'
19
+
20
+ opts.on('--init', 'Initialize swan config file') do |v|
21
+ options[:init] = true
22
+ end
23
+
24
+ opts.on('-c', '--config config', 'Configuration file to use') do |c|
25
+ options[:config] = c
26
+ options[:init_params] = " -c #{c}"
27
+ end
28
+
29
+ opts.on('--only only', 'Comma-separated list of files, download only them') do |only|
30
+ options[:only] = only.split(',')
31
+ end
32
+
33
+ opts.on('-h', '--help', 'Show this help message') do
34
+ puts opts
35
+ exit
36
+ end
37
+ end.parse!
38
+
39
+ swan = Swan::Downloader.new
40
+
41
+ if options[:init]
42
+ # Create new config file
43
+ # Ask user to override if exists
44
+ swan.init(options[:config])
45
+ else
46
+ # Read config file
47
+ begin
48
+ files = YAML.load_file(options[:config])
49
+ rescue
50
+ puts "Can not find #{options[:config]} file. Please run `swan --init#{options[:init_params]}` to create it or choose another file."
51
+ exit
52
+ end
53
+
54
+ unless files
55
+ puts 'Nothing to download.'
56
+ exit
57
+ end
58
+
59
+ swan.download(files, options)
60
+ end
data/lib/swan.rb ADDED
@@ -0,0 +1,60 @@
1
+ require 'swan/version'
2
+
3
+ module Swan
4
+ class Downloader
5
+ def init(filename)
6
+ if File.file?(filename)
7
+ puts "File #{filename} already exists. Override? (y/N)"
8
+ input = gets.strip
9
+
10
+ return unless input == 'Y' || input == 'y'
11
+ end
12
+
13
+ open(File.join(File.dirname(__FILE__), 'swan', 'templates', 'config.yml')) do |template|
14
+ open(filename, 'wb') do |file|
15
+ file.puts template.read
16
+ puts "File #{filename} was successfully created."
17
+ end
18
+ end
19
+ end
20
+
21
+ def download(files, options)
22
+ files.each do |filename, params|
23
+ if params.nil? || params.empty?
24
+ puts "Skipping #{filename}"
25
+ next
26
+ end
27
+ keyname = filename
28
+ if params.is_a? String
29
+ url = params
30
+ else
31
+ url = params['url']
32
+
33
+ filename = params['filename'] if params.key? 'filename'
34
+
35
+ filename = File.join(params['dir'], filename) if params.key? 'dir'
36
+ end
37
+
38
+ if (!options[:only].empty? && options[:only].include?(keyname)) || options[:only].empty?
39
+ download_file filename, url
40
+ end
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def download_file(filename, url)
47
+ print "Trying to download from #{url} to #{filename} ... "
48
+ begin
49
+ open(filename, 'wb') do |file|
50
+ file.puts open(url).read
51
+ puts 'done.'
52
+ end
53
+ rescue OpenURI::HTTPError => ex
54
+ puts "\nError while accessing remote file: #{ex.message}"
55
+ rescue => ex
56
+ puts "\nError during download: #{ex.message}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ # Specify files to be downloaded in this file
2
+ #
3
+ # rubocop:
4
+ # url: 'http://example.com/.rubocop.yml'
5
+ # filename: '.rubocop.yml'
6
+ # dir: '.'
7
+ #
8
+ # Root level elements are key names, which can be referenced in command line if needed.
9
+ #
10
+ # url - location of the file to be downloaded. Can be local (relative or absolute) or remote.
11
+ # save_to - filename to save file to. If not specified, root name will be used.
12
+ # dir - where to save file. Current directory by default.
13
+ #
14
+ # rubocop1:
15
+ # url: 'http://example.com/rubocop.yml'
16
+ # filename: '.rubocop.yml'
17
+ # dir: './app'
18
+ #
19
+ # Will download to ./app/.rubocop.yml
20
+ #
21
+ # rubocop2:
22
+ # url: 'http://example.com/rubocop.yml'
23
+ # filename: '.rubocop.yml'
24
+ #
25
+ # Will download to ./.rubocop.yml
26
+ #
27
+ # .rubocop.yaml:
28
+ # url: 'http://example.com/rubocop.yml'
29
+ #
30
+ # Will download to ./.rubocop.yaml
31
+ #
32
+ # Simplest example:
33
+ #
34
+ # .rubocop.yml: 'http://example.com/my_rubocop.yml'
35
+ #
36
+ # Will download to ./.rubocop.yml
@@ -0,0 +1,3 @@
1
+ module Swan
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/swan.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'swan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'swan'
8
+ spec.version = Swan::VERSION
9
+ spec.authors = ['Stas Karpov']
10
+ spec.email = ['gilbert_90@mail.ru']
11
+
12
+ spec.summary = 'Helps automate synchronization of common files between projects'
13
+ spec.homepage = 'https://github.com/staskjs/swan'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'bin'
18
+ spec.executables = ['swan']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.11'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Stas Karpov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-12 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ description:
56
+ email:
57
+ - gilbert_90@mail.ru
58
+ executables:
59
+ - swan
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - bin/swan
74
+ - lib/swan.rb
75
+ - lib/swan/templates/config.yml
76
+ - lib/swan/version.rb
77
+ - swan.gemspec
78
+ homepage: https://github.com/staskjs/swan
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Helps automate synchronization of common files between projects
102
+ test_files: []