xf-generators 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.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in xf-generators.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate concern Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,67 @@
1
+ class ConcernGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :models, :type => :array, :banner => "model model"
4
+
5
+ # TODO добавить проверку на существование файла модели.
6
+ def validation
7
+ raise(NameError, "#{file_path.classify} model was not found.") unless File.exists?(File.join("app/models", "#{file_path}.rb"))
8
+ end
9
+
10
+ def generate_concern
11
+ models.reverse.each do |model|
12
+ @model_name = model.camelize
13
+
14
+ model(File.join("app/models", "#{file_path}.rb"), "include Models::#{class_name}::#{@model_name}Methods\n")
15
+
16
+ template "concern_model.rb", "lib/models/#{file_path}/#{model}_methods.rb"
17
+ end
18
+ end
19
+
20
+ private
21
+ def first_line_ends
22
+ /\A.*\n/
23
+ end
24
+
25
+ def model(file, model_code)
26
+ log :model, model_code
27
+ sentinel = /^class.+$/
28
+
29
+ in_root do
30
+ inject_into_file file, "\n #{model_code}\n", { :after => sentinel, :verbose => false }
31
+ end
32
+ end
33
+ end
34
+
35
+ module Xf
36
+ module Generators
37
+ class ConcernGenerator < Rails::Generators::NamedBase
38
+ source_root File.expand_path('../templates', __FILE__)
39
+ argument :models, :type => :array, :banner => "model model"
40
+
41
+ def validation
42
+ raise(NameError, "#{file_path.classify} model was not found.") unless File.exists?(File.join("app/models", "#{file_path}.rb"))
43
+ end
44
+
45
+ def generate_concern
46
+ models.reverse.each do |model|
47
+ @model_name = model.camelize
48
+
49
+ model(File.join("app/models", "#{file_path}.rb"), "include Models::#{class_name}::#{@model_name}Methods\n")
50
+
51
+ template "concern_model.rb", "lib/models/#{file_path}/#{model}_methods.rb"
52
+ template "concern_spec.rb", "spec/lib/models/#{file_path}/#{model}_methods_spec.rb"
53
+ end
54
+ end
55
+
56
+ private
57
+ def model(file, model_code)
58
+ log :model, model_code
59
+ sentinel = /^class.+$/
60
+
61
+ in_root do
62
+ inject_into_file file, "\n #{model_code}\n", { :after => sentinel, :verbose => false }
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ module Models
2
+ module <%= class_name %>
3
+ module <%= @model_name %>Methods
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Add your class evaluated code here.
8
+ end
9
+
10
+ module ClassMethods
11
+ # Add your class methods here.
12
+ end
13
+
14
+ module InstanceMethods
15
+ # Add your instance methods here.
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ describe <%= class_name %>, '(<%= @model_name %> Methods)' do
2
+ pending "add some examples to (or delete) #{__FILE__}"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "xf-generators"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Andrey Ognevsky"]
8
+ s.email = ["a.ognevsky@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Generate concern files with grace.}
11
+ s.description = %q{Generate concern files with grace.}
12
+
13
+ s.rubyforge_project = "xf-generators"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xf-generators
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrey Ognevsky
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-09 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Generate concern files with grace.
23
+ email:
24
+ - a.ognevsky@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .DS_Store
33
+ - .gitignore
34
+ - Gemfile
35
+ - Rakefile
36
+ - lib/.DS_Store
37
+ - lib/generators/.DS_Store
38
+ - lib/generators/xf/.DS_Store
39
+ - lib/generators/xf/concern/USAGE
40
+ - lib/generators/xf/concern/concern_generator.rb
41
+ - lib/generators/xf/concern/templates/concern_model.rb
42
+ - lib/generators/xf/concern/templates/concern_spec.rb
43
+ - xf-generators.gemspec
44
+ has_rdoc: true
45
+ homepage: ""
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project: xf-generators
74
+ rubygems_version: 1.4.2
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Generate concern files with grace.
78
+ test_files: []
79
+