webnames 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d2f86594020cd71d6012077c7cffb931baa4b3e
4
- data.tar.gz: 402feb8e9d281c01988d6d0a99e32669385d2ee7
3
+ metadata.gz: 6b6b3236ac3fd31f21655a63483ab84a657e34e1
4
+ data.tar.gz: 9fafe45b9e62ba6faeab35e3267b2abf16005383
5
5
  SHA512:
6
- metadata.gz: c16fd211f90ea4532d5fc8c26f5da625625227b1d8cbb1f055fcec76bc59e06d8039b4ee1f3cc8333094141cf7fd31ec777d44bfa25d080094a3c725e0e798c5
7
- data.tar.gz: 08633f64ca861835776df07c54b4c3134ed0f0620fcd240af4cf71fee88c5cdaf843decf0a0cd9a512e2623bd552294be1c0146407454622477ed845c1b7e43a
6
+ metadata.gz: fa3ec000dff1c7d34bcb1df882efbb1d834b6554b8d247643d6e6c303da48ba8fc0e24ca2a7848340af4eff86411cce0fb5dff74ac2d37f14611cce67e78a22c
7
+ data.tar.gz: fb2d1bc82e454c071efc2dd54cc5339606fc75bf66a37873e87f1bb6142ad720c78a19b793a9b62db5d0843ac93f838121074d93b2b10611ee7eda69daaab623
data/Rakefile CHANGED
@@ -6,6 +6,14 @@ end
6
6
 
7
7
  require 'rdoc/task'
8
8
 
9
+ desc "Run tests"
10
+ task default: :spec
11
+
12
+ desc "Run all specs"
13
+ task :spec do
14
+ exec "bundle exec rspec"
15
+ end
16
+
9
17
  RDoc::Task.new(:rdoc) do |rdoc|
10
18
  rdoc.rdoc_dir = 'rdoc'
11
19
  rdoc.title = 'Webname'
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a model and a migration file for the webnames
3
+
4
+ Example:
5
+ rails generate webnames:install
6
+
7
+ This will create:
8
+ app/models/webname.rb
@@ -0,0 +1,20 @@
1
+ require 'rails/generators/active_record'
2
+ require 'active_support/core_ext'
3
+
4
+ class Webnames::InstallGenerator < ActiveRecord::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ argument :name, :type => :string, :default => "Webname", :banner => "Webname"
8
+
9
+ def generate_model
10
+ copy_file "webnames-active_record.rb", model_path
11
+ end
12
+
13
+ def copy_webnames_migration
14
+ migration_template "migration.rb", "db/migrate/webnames_create_#{table_name}"
15
+ end
16
+
17
+ def model_path
18
+ File.join("app", "models", "#{file_path}.rb")
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
- class WebnameCreate<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class WebnamesCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table(:<%= table_name %>) do |t|
4
4
  t.string :webname
@@ -1,3 +1,8 @@
1
1
  class Webname < ActiveRecord::Base
2
2
  belongs_to :resource, :polymorphic => true
3
+ validates_uniqueness_of :webname
4
+
5
+ def to_s
6
+ self.webname
7
+ end
3
8
  end
@@ -1,4 +1,4 @@
1
1
  # desc "Explaining what the task does"
2
- # task :webname do
2
+ # task :webnames do
3
3
  # # Task goes here
4
4
  # end
@@ -1,4 +1,4 @@
1
- module Webname
1
+ module Webnames
2
2
  class Engine < ::Rails::Engine
3
3
  config.generators do |g|
4
4
  g.test_framework :rspec, :fixture => false
@@ -0,0 +1,28 @@
1
+ require 'active_support/concern'
2
+
3
+ module Webnames
4
+ module ClassMacros
5
+ def webnameable
6
+ include Webnames::Webnameable
7
+ end
8
+ end
9
+
10
+ module Webnameable
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ has_one :webname, as: :resource
15
+ default_scope -> { includes(:webname) }
16
+
17
+ def to_param
18
+ self.webname
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ def find(input, *args)
24
+ input.to_i == 0 ? where(webnames: {webname: input}).first : super
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ def webnames_for(resources_name, *args, &block)
4
+ options = args.extract_options!
5
+
6
+ options.reverse_merge! param: :webname
7
+
8
+ options_with_blank_path = options.reverse_merge path: '', except: [:new, :create, :index]
9
+ options_with_path = options.reverse_merge except: [:show, :edit, :update, :destroy]
10
+
11
+ resources resources_name, options_with_blank_path, &block
12
+ resources resources_name, options_with_path, &block
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Webnames
2
+ VERSION = "0.2.0"
3
+ end
data/lib/webnames.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "webnames/engine"
2
+ require "webnames/rails/routes"
3
+ require "webnames/rails/active_record"
4
+
5
+ module Webnames
6
+ end
7
+
8
+ ActiveRecord::Base.send(:extend, Webnames::ClassMacros)
metadata CHANGED
@@ -1,61 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webnames
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadjow Medeiros Leão
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>'
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>'
27
+ - - ">"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'
33
33
  - !ruby/object:Gem::Dependency
34
- name: pg
34
+ name: rspec-rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: rspec-rails
48
+ name: pry
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  description: webname(nickname, username) solution for Rails applications
@@ -65,20 +65,18 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
- - config/routes.rb
69
- - lib/generators/active_record/active_record_generator.rb
70
- - lib/generators/active_record/templates/migration.rb
71
- - lib/generators/active_record/USAGE
72
- - lib/generators/active_record/webname_generator.rb
73
- - lib/generators/webname/templates/webname-active_record.rb
74
- - lib/generators/webname/USAGE
75
- - lib/generators/webname/webname_generator.rb
76
- - lib/tasks/webname_tasks.rake
77
- - lib/webname/engine.rb
78
- - lib/webname/version.rb
79
- - lib/webname.rb
80
68
  - MIT-LICENSE
81
69
  - Rakefile
70
+ - lib/generators/webnames/install/USAGE
71
+ - lib/generators/webnames/install/install_generator.rb
72
+ - lib/generators/webnames/install/templates/migration.rb
73
+ - lib/generators/webnames/install/templates/webnames-active_record.rb
74
+ - lib/tasks/webnames_tasks.rake
75
+ - lib/webnames.rb
76
+ - lib/webnames/engine.rb
77
+ - lib/webnames/rails/active_record.rb
78
+ - lib/webnames/rails/routes.rb
79
+ - lib/webnames/version.rb
82
80
  homepage: https://github.com/sadjow/webnames
83
81
  licenses: []
84
82
  metadata: {}
@@ -88,17 +86,17 @@ require_paths:
88
86
  - lib
89
87
  required_ruby_version: !ruby/object:Gem::Requirement
90
88
  requirements:
91
- - - '>='
89
+ - - ">="
92
90
  - !ruby/object:Gem::Version
93
91
  version: '0'
94
92
  required_rubygems_version: !ruby/object:Gem::Requirement
95
93
  requirements:
96
- - - '>='
94
+ - - ">="
97
95
  - !ruby/object:Gem::Version
98
96
  version: '0'
99
97
  requirements: []
100
98
  rubyforge_project:
101
- rubygems_version: 2.0.6
99
+ rubygems_version: 2.2.2
102
100
  signing_key:
103
101
  specification_version: 4
104
102
  summary: webname(nickname, username) solution for Rails
data/config/routes.rb DELETED
@@ -1,2 +0,0 @@
1
- Rails.application.routes.draw do
2
- end
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate active_record Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,3 +0,0 @@
1
- class ActiveRecordGenerator < Rails::Generators::NamedBase
2
- source_root File.expand_path('../templates', __FILE__)
3
- end
@@ -1,26 +0,0 @@
1
- require 'rails/generators/active_record'
2
- require 'active_support/core_ext'
3
-
4
- module ActiveRecord
5
- module Generators
6
- class WebnameGenerator < ActiveRecord::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- def generate_model
10
- invoke "active_record:model", [ name ], :migration => false
11
- end
12
-
13
- def copy_webname_migration
14
- migration_template "migration.rb", "db/migrate/webname_create_#{table_name}"
15
- end
16
-
17
- def model_path
18
- File.join("app", "models", "#{file_path}.rb")
19
- end
20
-
21
- def model_content
22
- "belongs_to :resource, :polymorphic => true"
23
- end
24
- end
25
- end
26
- end
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate webname Thing
6
-
7
- This will create:
8
- what/will/it/create
@@ -1,20 +0,0 @@
1
- module Webname
2
- module Generators
3
- class WebnameGenerator < Rails::Generators::NamedBase
4
- class_option :orm, :type => :string, :default => "active_record"
5
- argument :klass_name, :type => :string, :default => "Webname"
6
-
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- hook_for :orm, :required => true
10
-
11
- desc "Generates a model and a migration file for the webnames"
12
-
13
- def self.start(args, config)
14
- klass_name = args.size > 1 ? args[1] : "Webname"
15
- args.insert(1, klass_name) # 0 being the view name
16
- super
17
- end
18
- end
19
- end
20
- end
@@ -1,3 +0,0 @@
1
- module Webname
2
- VERSION = "0.0.1"
3
- end
data/lib/webname.rb DELETED
@@ -1,4 +0,0 @@
1
- require "webname/engine"
2
-
3
- module Webname
4
- end