diff_resource 0.1.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ad6f41ec3ad9423f89448b5333f72916e2e27e0
4
+ data.tar.gz: f9ad3f44844d83f1095acfb24c203ccf18222a56
5
+ SHA512:
6
+ metadata.gz: 74e7bec7cfd0aacc680d27636cdf55c5b8751fdc33da706a5afa45a3c025ae55e99b6a167f526a5ff615c01d60f74addc226763e300a72616f4d8a58ea1fc205
7
+ data.tar.gz: daf3b517b903c5a03341b6748639085c318cfa05f2ac720a5a64f6fe8610efbab419592f51e7717bc629bfc2aee1c2ce12a248992c1b261ed0bde141f838202a
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Katsuya SHIMABUKURO
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,59 @@
1
+ # DiffResource
2
+ [![Gem Version](https://badge.fury.io/rb/diff_resource.svg)](https://badge.fury.io/rb/diff_resource)
3
+ [![Dependency Status](https://gemnasium.com/katsugeneration/diff-resource.svg)](https://gemnasium.com/katsugeneration/diff-resource)
4
+ [![Build Status](https://travis-ci.org/katsugeneration/diff-resource.svg?branch=master)](https://travis-ci.org/katsugeneration/diff-resource)
5
+ [![Code Climate](https://codeclimate.com/github/katsugeneration/diff-resource/badges/gpa.svg)](https://codeclimate.com/github/katsugeneration/diff-resource)
6
+ [![Test Coverage](https://codeclimate.com/github/katsugeneration/diff-resource/badges/coverage.svg)](https://codeclimate.com/github/katsugeneration/diff-resource/coverage)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'diff_resource'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install diff_resource
23
+
24
+ ## Usage
25
+
26
+ output your resource file's diff list, you execute under command
27
+
28
+ Usage:
29
+ ```bash
30
+ diff_resource create <directory> <comparison> <file> [<options>] -t, --type=TYPE
31
+ ```
32
+
33
+ Options:
34
+ - -t, --type=TYPE : resource file type
35
+ - -o, [--output=OUTPUT] : output file path.
36
+ - -c, [--compare=COMPARE] : comparison target type. other directory or git object
37
+
38
+ Arguments:
39
+ - directory: resource file root path
40
+ - comparison: compare directory path or git hash
41
+ - file: resource file name format ex) test.resource, \*.resource, \*-en.resource
42
+
43
+
44
+ Show detail, you execute under command
45
+ ```bash
46
+ diff_resource help create
47
+ ```
48
+
49
+ ## Development
50
+
51
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/katsugeneration/diff-resource/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/bin/diff_resource ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
4
+ require "diff_resource"
5
+ require "diff_resource/cli"
6
+
7
+ DiffResource::Cli.start ARGV
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'diff_resource/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "diff_resource"
8
+ spec.version = DiffResource::VERSION
9
+ spec.authors = ["Katsuya SHIMABUKURO"]
10
+ spec.email = ["katsu.generation.888@gmail.com"]
11
+
12
+ spec.summary = "Output resource file diffs"
13
+ spec.description = "Output resource file diffs.You can set resource directory, resource type, output file path, etc..."
14
+ spec.homepage = "https://github.com/katsugeneration/diff-resource"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
26
+ file =~ %r{^(?:
27
+ spec/.*
28
+ |Gemfile
29
+ |Rakefile
30
+ |\.gitignore
31
+ |\.rubocop.yml
32
+ |\.travis.yml
33
+ )$}x
34
+ end
35
+ spec.bindir = "bin"
36
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec"
42
+ spec.add_runtime_dependency "thor"
43
+ end
@@ -0,0 +1,14 @@
1
+ require "diff_resource/version"
2
+
3
+ require "diff_resource/inputer/directory_inputer"
4
+ require "diff_resource/inputer/git_inputer"
5
+
6
+ require "diff_resource/outputer"
7
+
8
+ require "diff_resource/comparer"
9
+
10
+ require "diff_resource/parser/parser"
11
+ require "diff_resource/parser/resx_parser"
12
+
13
+ require "diff_resource/factory/parser_factory"
14
+ require "diff_resource/factory/inputer_factory"
@@ -0,0 +1,35 @@
1
+ require 'thor'
2
+
3
+ module DiffResource
4
+ class Cli < Thor
5
+ desc "create <directory> <comparison> <file> [<options>]", <<-EOS
6
+ create resource diff file
7
+ - directory: resource file root path
8
+ - comparison: compare directory path or git object
9
+ - file: resource file name format
10
+ ex) test.resource, *.resource, *-en.resource
11
+
12
+ EOS
13
+ method_option :type, :aliases => "-t", :enum => %w(resx), :required => true, :desc => "resource file type"
14
+ method_option :output, :aliases => "-o", :type => :string, :default => "./diffs.csv", :desc => "output file path."
15
+ method_option :compare, :aliases => "-c", :enum => %w(dir git), :default => "dir", :desc => "comparison target type. other directory or git hash"
16
+ def create target_dir = nil, comparison_target = nil, target_file = nil
17
+ parser = DiffResource::ParserFactory.create options[:type]
18
+ inputer = DiffResource::InputerFactory.create "dir"
19
+ comparison_inputer = DiffResource::InputerFactory.create options[:compare]
20
+
21
+ # when git pattern, comparison target is same to new resources and comprison_target is git object
22
+ if options[:compare] == "git"
23
+ comparison_inputer.reference = comparison_target
24
+ comparison_target = target_dir
25
+ end
26
+
27
+ new_resources = inputer.parse_files target_dir, target_file, parser
28
+ old_resources = comparison_inputer.parse_files comparison_target, target_file, parser
29
+
30
+ comparer = DiffResource::Comparer.new new_resources, old_resources
31
+ outputer = DiffResource::Outputer.new
32
+ outputer.output comparer.diffs, options[:output]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+
2
+ module DiffResource
3
+ class Comparer
4
+ @@struct_diff = Struct.new "Diff", :key, :value, :old, :status
5
+
6
+ def initialize new_resources, old_resources
7
+ @diffs = new_resources.map do |new_resource|
8
+ ret = nil
9
+ old_resources.each do |old_resource|
10
+ next if new_resource.key != old_resource.key
11
+
12
+ status = (new_resource.value == old_resource.value) ? :completed : :modified
13
+ ret = @@struct_diff.new(new_resource.key, new_resource.value, old_resource.value, status)
14
+ break
15
+ end
16
+
17
+ next ret unless ret.nil?
18
+
19
+ @@struct_diff.new(new_resource.key, new_resource.value, "", :new)
20
+ end
21
+ end
22
+
23
+ attr_reader :diffs
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ module DiffResource
2
+ class InputerFactory
3
+ def self.create type
4
+ return case type
5
+ when "dir"
6
+ DiffResource::DirectoryInputer.new
7
+ when "git"
8
+ DiffResource::GitInputer.new
9
+ else
10
+ fail ArgumentError.new, 'undefined parser type'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module DiffResource
3
+ class ParserFactory
4
+ def self.create type
5
+ return case type
6
+ when "resx"
7
+ DiffResource::ResxParser.new
8
+ else
9
+ fail ArgumentError.new, 'undefined parser type'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+
2
+ module DiffResource
3
+ class DirectoryInputer
4
+ def parse_file file_name, parser
5
+ ret = []
6
+ begin
7
+ open file_name do |file|
8
+ ret = parser.parse file.read
9
+ end
10
+ rescue => e
11
+ p e.message
12
+ end
13
+
14
+ return ret
15
+ end
16
+
17
+ def parse_files path, extension, parser
18
+ resources = []
19
+
20
+ if FileTest.directory? path
21
+ Dir.foreach path do |file|
22
+ next if /^\.+$/ =~ file
23
+ resources += parse_files File.absolute_path(file, path), extension, parser
24
+ end
25
+ elsif FileTest.file? path
26
+ resources += parse_file path, parser if %r{^.*\/#{extension}$} =~ path
27
+ end
28
+
29
+ return resources
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+
2
+ module DiffResource
3
+ class GitInputer
4
+ attr_accessor :reference
5
+
6
+ def parse_file file_name, parser
7
+ ret = []
8
+
9
+ contents = `git show #{reference}:#{file_name}`
10
+ ret = parser.parse contents if $?.exitstatus == 0
11
+ return ret
12
+ end
13
+
14
+ def parse_files path, extension, parser
15
+ resources = []
16
+
17
+ if directory? path
18
+ contents = `git ls-tree --name-only #{reference}:#{path}`
19
+ contents.split("\n").each do |file|
20
+ resources += parse_files (path + "/" + file), extension, parser
21
+ end
22
+ elsif file? path
23
+ resources += parse_file path, parser if %r{^.*\/#{extension}$} =~ path
24
+ end
25
+
26
+ return resources
27
+ end
28
+
29
+ def directory? path
30
+ return type? path, "tree"
31
+ end
32
+
33
+ def file? path
34
+ return type? path, "blob"
35
+ end
36
+
37
+ def type? path, type
38
+ type_str = `git cat-file -t #{reference}:#{path}`
39
+ return type_str.delete("\n") == type if $?.exitstatus == 0
40
+ return false
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module DiffResource
3
+ class Outputer
4
+ def output diffs, file_name
5
+ open file_name, "w" do |file|
6
+ file.write "key,value,old,status\n"
7
+ diffs.each do |diff|
8
+ file.write("#{diff.key},#{diff.value},#{diff.old},#{diff.status}\n")
9
+ end
10
+ end
11
+ rescue => e
12
+ p e.message
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+
2
+ module DiffResource
3
+ class Parser
4
+ @@resource = Struct.new "Resource", :key, :value
5
+
6
+ def parse str
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'rexml/document'
2
+
3
+ module DiffResource
4
+ class ResxParser < Parser
5
+ def parse str
6
+ ret = []
7
+ begin
8
+ resx = REXML::Document.new str
9
+
10
+ REXML::XPath.match(resx, "/root/data").map do |data|
11
+ type = data.attribute("type")
12
+ next unless type.nil?
13
+
14
+ key = data.attribute("name").value
15
+ value_element = data.elements["value"]
16
+ value = value_element ? value_element.text : nil
17
+
18
+ ret << @@resource.new(key, value)
19
+ end
20
+ rescue => e
21
+ p e.message
22
+ end
23
+
24
+ return ret
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module DiffResource
2
+ VERSION = "0.1.3"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diff_resource
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Katsuya SHIMABUKURO
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-17 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
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: Output resource file diffs.You can set resource directory, resource type,
70
+ output file path, etc...
71
+ email:
72
+ - katsu.generation.888@gmail.com
73
+ executables:
74
+ - diff_resource
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - CODE_OF_CONDUCT.md
79
+ - LICENSE.txt
80
+ - README.md
81
+ - bin/diff_resource
82
+ - diff_resource.gemspec
83
+ - lib/diff_resource.rb
84
+ - lib/diff_resource/cli.rb
85
+ - lib/diff_resource/comparer.rb
86
+ - lib/diff_resource/factory/inputer_factory.rb
87
+ - lib/diff_resource/factory/parser_factory.rb
88
+ - lib/diff_resource/inputer/directory_inputer.rb
89
+ - lib/diff_resource/inputer/git_inputer.rb
90
+ - lib/diff_resource/outputer.rb
91
+ - lib/diff_resource/parser/parser.rb
92
+ - lib/diff_resource/parser/resx_parser.rb
93
+ - lib/diff_resource/version.rb
94
+ homepage: https://github.com/katsugeneration/diff-resource
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Output resource file diffs
118
+ test_files: []