rails-graft 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b97601e1eabbf9bb453c405651d17de7db7bd9c
4
+ data.tar.gz: 6d2315b3f55cdbc2a7ebb6f4cb6f366e73e32331
5
+ SHA512:
6
+ metadata.gz: 73b3487a5a19945effd88375121b4ef4289db1e647694d7215ad680180c0711591478f62b7da3abdb46ef410eeee6229d3bb8ddd7206e2067cdbc8924e208b78
7
+ data.tar.gz: 2310df74e2e919fedf196af0ecda93e89ac3998cd6857c2f1e2eabc977f00d20edf2d52bc05bbf004c4b1fcea2791c43a160d55f5f47c383f5613bb2a48794b0
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-graft.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Blake Taylor
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.
@@ -0,0 +1,31 @@
1
+ # rails-graft
2
+
3
+ Replicate Rails controllers, models and views like a boss.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-graft'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rails-graft
18
+
19
+ ## Usage
20
+
21
+ From the root of your rails project.
22
+
23
+ $ rails-graft <source> <target>
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,60 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # Simple tool to graft controller, model and views in a rails application onto a
4
+ # new set.
5
+
6
+ require 'active_support/inflector'
7
+
8
+ if ARGV.empty?
9
+ puts <<-EOF
10
+ Grafts a portion of a rails application onto another set (Controller, model, views, etc...)
11
+
12
+ Usage:
13
+
14
+ rails-graft <source> <target>
15
+
16
+ Example:
17
+
18
+ rails-graft post comment
19
+
20
+ EOF
21
+ exit
22
+ end
23
+
24
+ source = ARGV[0]
25
+ target = ARGV[1]
26
+
27
+ source = source.singularize.underscore
28
+ target = target.singularize.underscore
29
+
30
+ plural_source = source.pluralize
31
+ plural_target = target.pluralize
32
+
33
+ # Should do plural versions too, and first.
34
+ @model_file_path = "app/models/#{target}.rb"
35
+ @controller_file_path = "app/controllers/#{plural_target}_controller.rb"
36
+ @view_path = "app/views/#{plural_target}"
37
+
38
+ # Copy das files
39
+ `cp app/models/#{source}.rb #{@model_file_path}`
40
+ `cp app/controllers/#{plural_source}_controller.rb #{@controller_file_path}`
41
+ `mkdir #{@view_path}`
42
+ Dir.glob("app/views/#{plural_source}/*") do |file|
43
+ `cp #{file} #{file.gsub(source, target)}`
44
+ end
45
+
46
+ # Need one of these for replaceing shit.
47
+ def sub_pattern(match, replacement)
48
+ `sed -i "" -e "s/#{match}/#{replacement}/g" #{@controller_file_path}`
49
+ `sed -i "" -e "s/#{match}/#{replacement}/g" #{@model_file_path}`
50
+
51
+ Dir.glob("#{@view_path}/*.*") do |file|
52
+ `sed -i "" -e "s/#{match}/#{replacement}/g" #{file}`
53
+ end
54
+ end
55
+
56
+ # Replace all the things.
57
+ sub_pattern(plural_source.camelize, plural_target.camelize)
58
+ sub_pattern(plural_source.underscore, plural_target.underscore)
59
+ sub_pattern(source.camelize, target.camelize)
60
+ sub_pattern(source.underscore, target.underscore)
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rails-graft"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Blake Taylor"]
9
+ spec.email = ["blakefrost@gmail.com"]
10
+ spec.description = %q{Replicate Rails controllers, models and views like a boss.}
11
+ spec.summary = %q{
12
+ Copies controller, model and views from a source name to a target name.
13
+ Useful for implementing a new peice of functionlaity based off of some
14
+ exisitng functionalitily.
15
+ }
16
+ spec.homepage = ""
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-graft
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Blake Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-18 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Replicate Rails controllers, models and views like a boss.
42
+ email:
43
+ - blakefrost@gmail.com
44
+ executables:
45
+ - rails-graft
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - bin/rails-graft
55
+ - rails-graft.gemspec
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.0
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Copies controller, model and views from a source name to a target name. Useful
80
+ for implementing a new peice of functionlaity based off of some exisitng functionalitily.
81
+ test_files: []