to_file 1.0.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: d2a2870a34570aa5e49c456137e02c233cfe1faf
4
+ data.tar.gz: 955bd53c545fd715e9a9820834411cb52ab2352c
5
+ SHA512:
6
+ metadata.gz: 8e93ac6e14afc36a7a8c92fe0c17df9811a7924e9a26b6511a37a0fe513fe1356f78e62ff53e00eaa0d10fc5da74305fbfe2e2b8dc00a77ef5df92636923121a
7
+ data.tar.gz: 2554e46fb969e624006d9005f1162e728190053f2243344f7604baea3b68071fa5afce840b04591b090a562bb8c9b1d5db337158f1c67f124f0323298bee6dc6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,4 @@
1
+ example_id | status | run_time |
2
+ --------------------------- | ------ | --------------- |
3
+ ./spec/to_file_spec.rb[1:1] | passed | 0.00105 seconds |
4
+ ./spec/to_file_spec.rb[1:2] | passed | 0.01174 seconds |
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in to_file.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2018 Johnny Yu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Introduction about ToFile
2
+
3
+ This gem is aim to transform the format of objects to be suitable for exporting , and export them into specific files. </br>
4
+
5
+ Currently supported export files: </br>
6
+ * `YAML`
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'to_file'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install to_file
23
+
24
+ ## Usage
25
+
26
+ It's very easy to use and the common usage is: <br />
27
+
28
+ ```ruby
29
+ ToFile::To.NAME_OF_FILE(object, export_path = './exaple.FILE_TYPE', confirmation = true)
30
+ ```
31
+
32
+ Some explanation about the parameters: <br />
33
+
34
+ * `object`: The ruby object which you want to export into files. <br />
35
+ * `export_path`(optional): The path where you want to generate your export file. Default will be './example.FILE_TYPE' such as './example.yml' <br />
36
+ * `confirmation`(optional): To confirm if you want to overwrite the existing file from export_path. <br />
37
+
38
+ ## Here are some samples:
39
+
40
+ * YAML
41
+
42
+ ```ruby
43
+ require 'to_file'
44
+
45
+ a = [1,2,3]
46
+ ToFile::To.yml(a, './test/a.yml', false)
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, 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).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/demaciaYu/to_file.
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 "to_file"
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/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
@@ -0,0 +1,3 @@
1
+ module ToFile
2
+ VERSION = "1.0.1"
3
+ end
data/lib/to_file.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "to_file/version"
2
+ require 'yaml'
3
+
4
+ module ToFile
5
+ class To
6
+ def self.yml(target_object, export_path = './example.yml', confirmation = true)
7
+ if confirmation && File.exist?(export_path)
8
+ puts 'Export canceled!'; exit unless confirm?(export_path)
9
+ end
10
+
11
+ File.open(export_path, 'w') { |f| f.write self.to_yml(target_object)}
12
+
13
+ puts "\e[32m successfully exported to ---> " + File.expand_path(export_path) + "\e[0m"
14
+ end
15
+
16
+ private
17
+
18
+ def self.to_yml(target_object)
19
+ begin
20
+ target_object.to_yaml
21
+ rescue
22
+ raise ArgumentError,
23
+ 'target_object can not be transformed to yaml format!'
24
+ end
25
+ end
26
+
27
+ def self.confirm?(export_path)
28
+ msg = "\033[31mWARNING '" + export_path + "' is already existing, do you"
29
+ msg += " want to overwrite it ??? please press 'y' or 'n' to confirm!( "
30
+ msg += "tip: confirm can be turned off by parameter): \033[0m"
31
+ puts msg
32
+
33
+ prompt = STDIN.gets.chomp
34
+
35
+ until %w(y n).include? prompt.downcase do
36
+ puts "\033[31mInvalid input, please input 'y' or 'n'\033[0m"
37
+ prompt = STDIN.gets.chomp
38
+ end
39
+
40
+ prompt.downcase == 'y' ? true : false
41
+ end
42
+ end
43
+ end
data/to_file.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "to_file/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "to_file"
8
+ spec.version = ToFile::VERSION
9
+ spec.authors = ["feiyang yu"]
10
+ spec.email = ["yufeiyang009334@gmail.com"]
11
+
12
+ spec.summary = %q{"The easist way to export object to files"}
13
+ spec.description = %q{"This gem is aim to transform the format of objects to be suitable for exporting , and export them into specific files. "}
14
+ spec.homepage = "https://github.com/demaciaYu/to_file"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_file
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - feiyang yu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-23 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
+ description: '"This gem is aim to transform the format of objects to be suitable for
56
+ exporting , and export them into specific files. "'
57
+ email:
58
+ - yufeiyang009334@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rspec_status"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/to_file.rb
73
+ - lib/to_file/version.rb
74
+ - to_file.gemspec
75
+ homepage: https://github.com/demaciaYu/to_file
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: '"The easist way to export object to files"'
99
+ test_files: []