hash_rocket 0.2.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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.swo
2
+ *.swp
3
+ *.bak
4
+ *.DS_Store
5
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hash_rocket.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hash_rocket (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.11.0)
11
+ rspec-core (~> 2.11.0)
12
+ rspec-expectations (~> 2.11.0)
13
+ rspec-mocks (~> 2.11.0)
14
+ rspec-core (2.11.1)
15
+ rspec-expectations (2.11.2)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.11.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ hash_rocket!
24
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 sparkplug
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.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # HashRocket
2
+
3
+ It's a simple gem to replace the old hash rocket
4
+
5
+ :symbolize_key => 'value'
6
+
7
+ between symbolize keys and their values by the new way:
8
+
9
+ symbolize_key: 'value'
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'hash_rocket'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install hash_rocket
24
+
25
+ ## Usage
26
+
27
+ Run your console
28
+
29
+ $ bundle exec rails c
30
+
31
+ Replace hash_rocket in every rails app files
32
+
33
+ rake hash_rocket:convert
34
+
35
+ Specify directory:
36
+
37
+ rake hash_rocket:convert FOLDER="/complete/path/to/directory"
38
+
39
+ Specify a single file path:
40
+
41
+ rake hash_rocket:convert TARGET="/complete/path/to/file"
42
+
43
+ Notes:
44
+
45
+ This script will prompt you the files he cannot parse
46
+ --> ERROR ON /path/to/the/problematic/file
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/hash_rocket/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["sparkplug"]
6
+ gem.email = ["mathieub@4nkh.com"]
7
+ gem.description = %q{find and replace old hash rocket}
8
+ gem.summary = %q{hash rocket explode}
9
+ gem.homepage = "https://github.com/4nkh/hash_rocket"
10
+
11
+ gem.add_development_dependency "rspec"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "hash_rocket"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = HashRocket::VERSION
19
+ end
@@ -0,0 +1,51 @@
1
+ require "hash_rocket/version"
2
+ require "hash_rocket/object"
3
+ module HashRocket
4
+
5
+ if defined?(Rails)
6
+ require "hash_rocket/railtie"
7
+ end
8
+
9
+ def self.convert(folder=nil, path=nil)
10
+ file_names = path_parameters(folder, path)
11
+ file_names.each do |fn|
12
+ if fn =~ /\.(rb|erb|haml|html|spec)/
13
+ begin
14
+ text = retrieve_file(folder, path, fn)
15
+ text = organize_symbols(text)
16
+ File.open(fn, "w") {|file| file.puts text }
17
+ rescue
18
+ puts "ERROR ON #{fn}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ private
24
+ def self.path_parameters(folder,path)
25
+ return path ? %W(#{path}) : Dir.glob("**/*") unless folder
26
+ return Dir[folder + "/**/*"] if folder
27
+ end
28
+
29
+ def self.retrieve_file(folder, path, fn)
30
+ return File.read(folder ? fn : Rails.root.to_s + "/" + fn) unless path
31
+ return File.read(path) if path
32
+ end
33
+
34
+ def self.organize_symbols(text)
35
+ result = text.scan(/((\ |^(?!::)):\w{1,}(\ {1,}|[\ {1,}]?)=>(\ {1,}|[\ ]?))/).flatten
36
+ text = match_symbols(text, result) if result
37
+ text
38
+ end
39
+
40
+ def self.match_symbols(text, strings)
41
+ strings.uniq.each do |str|
42
+ unless str.blank?
43
+ start, symbol, hash_rocket = str.match(/(^\ ?:*)(.+)((\ {1,}|[\ {1,}]?)=>(\ {1,}|[\ ]?))/).captures
44
+ text = text.gsub(str, start.gsub(':','') + symbol.gsub(/\ /, "") + ": ")
45
+ end
46
+ end
47
+ text
48
+ end
49
+
50
+ private_class_method :path_parameters, :retrieve_file, :organize_symbols, :match_symbols
51
+ end
@@ -0,0 +1,58 @@
1
+ class Object
2
+ # An object is blank if it's false, empty, or a whitespace string.
3
+ # For example, "", " ", +nil+, [], and {} are blank.
4
+ #
5
+ # This simplifies
6
+ #
7
+ # if !address.nil? && !address.empty?
8
+ #
9
+ # to
10
+ #
11
+ # if !address.blank?
12
+ def blank?
13
+ respond_to?(:empty?) ? empty? : !self
14
+ end
15
+
16
+ # An object is present if it's not blank.
17
+ def present?
18
+ !blank?
19
+ end
20
+ end
21
+
22
+ class NilClass #:nodoc:
23
+ def blank?
24
+ true
25
+ end
26
+ end
27
+
28
+ class FalseClass #:nodoc:
29
+ def blank?
30
+ true
31
+ end
32
+ end
33
+
34
+ class TrueClass #:nodoc:
35
+ def blank?
36
+ false
37
+ end
38
+ end
39
+
40
+ class Array #:nodoc:
41
+ alias_method :blank?, :empty?
42
+ end
43
+
44
+ class Hash #:nodoc:
45
+ alias_method :blank?, :empty?
46
+ end
47
+
48
+ class String #:nodoc:
49
+ def blank?
50
+ self !~ /\S/
51
+ end
52
+ end
53
+
54
+ class Numeric #:nodoc:
55
+ def blank?
56
+ false
57
+ end
58
+ end
@@ -0,0 +1,12 @@
1
+ require "hash_rocket"
2
+
3
+ module HashRocket
4
+ if defined? Rails::Railtie
5
+ require "rails"
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/hash_rocket.rake"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module HashRocket
2
+ VERSION = "0.2.3"
3
+ end
@@ -0,0 +1,6 @@
1
+ namespace "hash_rocket" do
2
+ desc "find and replace old hash_rockets"
3
+ task convert: :environment do
4
+ HashRocket.convert(ENV["FOLDER"], ENV["TARGET"])
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ :no_ident => 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ :normal => 'value'
8
+ :1digit => 'value'
9
+ :Capital => 'value'
10
+ :under_score => 'value'
11
+ :no_space=>'value'
12
+ :right_space=> 'value'
13
+ :left_space =>'value'
14
+ :left_double_space => 'value'
15
+ :right_double_space => 'value'
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ :no_ident => 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ :normal => 'value'
8
+ :1digit => 'value'
9
+ :Capital => 'value'
10
+ :under_score => 'value'
11
+ :no_space=>'value'
12
+ :right_space=> 'value'
13
+ :left_space =>'value'
14
+ :left_double_space => 'value'
15
+ :right_double_space => 'value'
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ :no_ident => 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ :normal => 'value'
8
+ :1digit => 'value'
9
+ :Capital => 'value'
10
+ :under_score => 'value'
11
+ :no_space=>'value'
12
+ :right_space=> 'value'
13
+ :left_space =>'value'
14
+ :left_double_space => 'value'
15
+ :right_double_space => 'value'
16
+ end
17
+
18
+ end
data/spec/data/file.rb ADDED
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ :no_ident => 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ :normal => 'value'
8
+ :1digit => 'value'
9
+ :Capital => 'value'
10
+ :under_score => 'value'
11
+ :no_space=>'value'
12
+ :right_space=> 'value'
13
+ :left_space =>'value'
14
+ :left_double_space => 'value'
15
+ :right_double_space => 'value'
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ :no_ident => 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ :normal => 'value'
8
+ :1digit => 'value'
9
+ :Capital => 'value'
10
+ :under_score => 'value'
11
+ :no_space=>'value'
12
+ :right_space=> 'value'
13
+ :left_space =>'value'
14
+ :left_double_space => 'value'
15
+ :right_double_space => 'value'
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ class Example
2
+
3
+ def foo
4
+ no_ident: 'value'
5
+ ::Class => 'value'
6
+ s::Class => 'value'
7
+ normal: 'value'
8
+ 1digit: 'value'
9
+ Capital: 'value'
10
+ under_score: 'value'
11
+ no_space: 'value'
12
+ right_space: 'value'
13
+ left_space: 'value'
14
+ left_double_space: 'value'
15
+ right_double_space: 'value'
16
+ end
17
+
18
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe HashRocket do
4
+
5
+ let(:folder) { File.expand_path('../..',__FILE__) + "/spec/data" }
6
+ let(:result) { "/result.txt" }
7
+
8
+ pending "write it"
9
+
10
+ describe "hash_rocket should be replaced if the file extention is supported: " do
11
+
12
+ before :each do
13
+ @file = folder + example.metadata[:file_ext]
14
+ @backup = File.read(@file)
15
+ HashRocket.convert(nil, @file)
16
+ @conversion = File.read(@file)
17
+ end
18
+
19
+ after :each do
20
+ File.open(@file, "w") {|f| f.puts @backup }
21
+ @backup.should eq File.read(@file)
22
+ end
23
+
24
+ it ".rb", :file_ext => "/file.rb" do
25
+ @conversion.should eq File.read(folder + result)
26
+ end
27
+
28
+ it ".erb", :file_ext => "/file.erb" do
29
+ @conversion.should eq File.read(folder + result)
30
+ end
31
+
32
+ it ".html", :file_ext => "/file.html" do
33
+ @conversion.should eq File.read(folder + result)
34
+ end
35
+
36
+ it ".haml", :file_ext => "/file.haml" do
37
+ @conversion.should eq File.read(folder + result)
38
+ end
39
+
40
+ it ".yml", :file_ext => "/file.yml" do
41
+ @conversion.should_not eq File.read(folder + result)
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'hash_rocket' # and any other gems you need
5
+ Dir[File.expand_path('../..',__FILE__) + "spec/data/*"].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.filter_run :focus => true
10
+ config.run_all_when_everything_filtered = true
11
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_rocket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sparkplug
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: find and replace old hash rocket
31
+ email:
32
+ - mathieub@4nkh.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - hash_rocket.gemspec
45
+ - lib/hash_rocket.rb
46
+ - lib/hash_rocket/object.rb
47
+ - lib/hash_rocket/railtie.rb
48
+ - lib/hash_rocket/version.rb
49
+ - lib/tasks/hash_rocket.rake
50
+ - spec/data/file.erb
51
+ - spec/data/file.haml
52
+ - spec/data/file.html
53
+ - spec/data/file.rb
54
+ - spec/data/file.yml
55
+ - spec/data/result.txt
56
+ - spec/hash_rocket_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/4nkh/hash_rocket
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.24
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: hash rocket explode
82
+ test_files:
83
+ - spec/data/file.erb
84
+ - spec/data/file.haml
85
+ - spec/data/file.html
86
+ - spec/data/file.rb
87
+ - spec/data/file.yml
88
+ - spec/data/result.txt
89
+ - spec/hash_rocket_spec.rb
90
+ - spec/spec_helper.rb