imyou 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25adebb4c4bd3d882502f7cf737a510e269037e66b0d99739b708006558b45e3
4
+ data.tar.gz: bd3b45051b198b474f8d741d78404ebbbb89acb215afe188655a7bfe8be4df44
5
+ SHA512:
6
+ metadata.gz: 96311348b980c930e1d4c94020a9ff8cec6d7a77c5abf263c015d7479bc70c69f06c2194e987a279021662564a0ba81e310183b6c024edfb7cc3ca9fd07b8cbd
7
+ data.tar.gz: 0b0bbaaaf2e240a6f78007e30f189fb4e3cddc38c3110e56912fa44de3350db927b48e4b3d155c30807e63552da2f30a13ee492de39447f31ea670d571d73567
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,17 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.3
5
+ - 2.4.5
6
+ - 2.3.8
7
+ gemfile:
8
+ - gemfiles/rails_5_2.gemfile
9
+ - gemfiles/rails_5_1.gemfile
10
+ - gemfiles/rails_5_0.gemfile
11
+ - gemfiles/rails_4_2.gemfile
12
+ branches:
13
+ only:
14
+ - master
15
+ - travis
16
+
17
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at chariderpato@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in imyou.gemspec
6
+ gemspec
7
+
8
+ gem 'pg'
9
+ gem 'rails'
@@ -0,0 +1,156 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ imyou (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (5.2.1)
10
+ actionpack (= 5.2.1)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailer (5.2.1)
14
+ actionpack (= 5.2.1)
15
+ actionview (= 5.2.1)
16
+ activejob (= 5.2.1)
17
+ mail (~> 2.5, >= 2.5.4)
18
+ rails-dom-testing (~> 2.0)
19
+ actionpack (5.2.1)
20
+ actionview (= 5.2.1)
21
+ activesupport (= 5.2.1)
22
+ rack (~> 2.0)
23
+ rack-test (>= 0.6.3)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
+ actionview (5.2.1)
27
+ activesupport (= 5.2.1)
28
+ builder (~> 3.1)
29
+ erubi (~> 1.4)
30
+ rails-dom-testing (~> 2.0)
31
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
32
+ activejob (5.2.1)
33
+ activesupport (= 5.2.1)
34
+ globalid (>= 0.3.6)
35
+ activemodel (5.2.1)
36
+ activesupport (= 5.2.1)
37
+ activerecord (5.2.1)
38
+ activemodel (= 5.2.1)
39
+ activesupport (= 5.2.1)
40
+ arel (>= 9.0)
41
+ activestorage (5.2.1)
42
+ actionpack (= 5.2.1)
43
+ activerecord (= 5.2.1)
44
+ marcel (~> 0.3.1)
45
+ activesupport (5.2.1)
46
+ concurrent-ruby (~> 1.0, >= 1.0.2)
47
+ i18n (>= 0.7, < 2)
48
+ minitest (~> 5.1)
49
+ tzinfo (~> 1.1)
50
+ arel (9.0.0)
51
+ builder (3.2.3)
52
+ coderay (1.1.2)
53
+ combustion (1.0.0)
54
+ activesupport (>= 3.0.0)
55
+ railties (>= 3.0.0)
56
+ thor (>= 0.14.6)
57
+ concurrent-ruby (1.1.3)
58
+ crass (1.0.4)
59
+ database_cleaner (1.7.0)
60
+ diff-lcs (1.3)
61
+ erubi (1.7.1)
62
+ globalid (0.4.1)
63
+ activesupport (>= 4.2.0)
64
+ i18n (1.1.1)
65
+ concurrent-ruby (~> 1.0)
66
+ loofah (2.2.3)
67
+ crass (~> 1.0.2)
68
+ nokogiri (>= 1.5.9)
69
+ mail (2.7.1)
70
+ mini_mime (>= 0.1.1)
71
+ marcel (0.3.3)
72
+ mimemagic (~> 0.3.2)
73
+ method_source (0.9.2)
74
+ mimemagic (0.3.2)
75
+ mini_mime (1.0.1)
76
+ mini_portile2 (2.3.0)
77
+ minitest (5.11.3)
78
+ nio4r (2.3.1)
79
+ nokogiri (1.8.5)
80
+ mini_portile2 (~> 2.3.0)
81
+ pg (1.1.3)
82
+ pry (0.12.2)
83
+ coderay (~> 1.1.0)
84
+ method_source (~> 0.9.0)
85
+ rack (2.0.6)
86
+ rack-test (1.1.0)
87
+ rack (>= 1.0, < 3)
88
+ rails (5.2.1)
89
+ actioncable (= 5.2.1)
90
+ actionmailer (= 5.2.1)
91
+ actionpack (= 5.2.1)
92
+ actionview (= 5.2.1)
93
+ activejob (= 5.2.1)
94
+ activemodel (= 5.2.1)
95
+ activerecord (= 5.2.1)
96
+ activestorage (= 5.2.1)
97
+ activesupport (= 5.2.1)
98
+ bundler (>= 1.3.0)
99
+ railties (= 5.2.1)
100
+ sprockets-rails (>= 2.0.0)
101
+ rails-dom-testing (2.0.3)
102
+ activesupport (>= 4.2.0)
103
+ nokogiri (>= 1.6)
104
+ rails-html-sanitizer (1.0.4)
105
+ loofah (~> 2.2, >= 2.2.2)
106
+ railties (5.2.1)
107
+ actionpack (= 5.2.1)
108
+ activesupport (= 5.2.1)
109
+ method_source
110
+ rake (>= 0.8.7)
111
+ thor (>= 0.19.0, < 2.0)
112
+ rake (10.5.0)
113
+ rspec (3.8.0)
114
+ rspec-core (~> 3.8.0)
115
+ rspec-expectations (~> 3.8.0)
116
+ rspec-mocks (~> 3.8.0)
117
+ rspec-core (3.8.0)
118
+ rspec-support (~> 3.8.0)
119
+ rspec-expectations (3.8.2)
120
+ diff-lcs (>= 1.2.0, < 2.0)
121
+ rspec-support (~> 3.8.0)
122
+ rspec-mocks (3.8.0)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.8.0)
125
+ rspec-support (3.8.0)
126
+ sprockets (3.7.2)
127
+ concurrent-ruby (~> 1.0)
128
+ rack (> 1, < 3)
129
+ sprockets-rails (3.2.1)
130
+ actionpack (>= 4.0)
131
+ activesupport (>= 4.0)
132
+ sprockets (>= 3.0.0)
133
+ thor (0.20.3)
134
+ thread_safe (0.3.6)
135
+ tzinfo (1.2.5)
136
+ thread_safe (~> 0.1)
137
+ websocket-driver (0.7.0)
138
+ websocket-extensions (>= 0.1.0)
139
+ websocket-extensions (0.1.3)
140
+
141
+ PLATFORMS
142
+ ruby
143
+
144
+ DEPENDENCIES
145
+ bundler (~> 1.16)
146
+ combustion (~> 1.0)
147
+ database_cleaner (~> 1.7)
148
+ imyou!
149
+ pg
150
+ pry (~> 0)
151
+ rails
152
+ rake (~> 10.0)
153
+ rspec (~> 3.0)
154
+
155
+ BUNDLED WITH
156
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 patorash
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.
@@ -0,0 +1,87 @@
1
+ # Imyou
2
+
3
+ [![Build Status](https://travis-ci.org/patorash/imyou.svg?branch=master)](https://travis-ci.org/patorash/imyou)
4
+
5
+ Imyou has feature of attaching popular name to ActiveRecord model.
6
+
7
+ Imyou mean nickname in japanease.
8
+
9
+ ## Installation
10
+
11
+ ### Rails 4.x and 5.x
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'imyou'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install imyou
26
+
27
+ ### Database Migrations
28
+
29
+ Imyou uses a imyou_nicknames table to store popular names information.
30
+ To generate and run the migration just use.
31
+
32
+ $ rails generate imyou:migration
33
+ $ rails db:migrate
34
+
35
+ ## Usage
36
+
37
+ ```ruby
38
+ class User < ApplicationRecord
39
+ has_imyou
40
+ end
41
+
42
+ @user = User.new(name: 'hoge')
43
+
44
+ # Add nickname.
45
+ @user.add_nickname('foo')
46
+ @user.nicknames # => ['foo']
47
+
48
+ # Add nicknames by Array.
49
+ @user.nicknames = %w(foo bar baz)
50
+ @user.nicknames # => ['foo', 'bar', 'baz']
51
+
52
+ # eager_load(LEFT OUTER JOIN)
53
+ User.with_nicknames
54
+
55
+ # Search users by nickname.
56
+ User.match_by_nickname('baz').exists? # => true
57
+ User.match_by_nickname('ba').exists? # => false
58
+ User.partial_match_by_nickname('baz').exists? # => true
59
+ User.partial_match_by_nickname('ba').exists? # => true
60
+
61
+ # Remove nickname.
62
+ @user.remove_nickname('foo')
63
+ @user.nicknames # => ['bar', 'baz']
64
+
65
+ # Remove all nicknames.
66
+ @user.remove_all_nicknames
67
+ @user.nicknames # => []
68
+ ```
69
+
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/patorash/imyou. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the Imyou project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/imyou/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "imyou"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pg', '~> 0.21'
4
+ gem 'rails', '~> 4.2.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pg', '~> 0.21'
4
+ gem 'rails', '~> 5.0.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pg', '~> 0.21'
4
+ gem 'rails', '~> 5.1.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pg', '~> 1.1.3'
4
+ gem 'rails', '~> 5.2.0'
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "imyou/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "imyou"
9
+ spec.version = Imyou::VERSION
10
+ spec.authors = ["patorash"]
11
+ spec.email = ["chariderpato@gmail.com"]
12
+
13
+ spec.summary = %q{Imyou has feature of attaching popular name to ActiveRecord model.}
14
+ spec.description = %q{Imyou has feature of attaching popular name to ActiveRecord model.}
15
+ spec.homepage = "https://github.com/patorash/imyou"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency 'pry', '~> 0'
31
+ spec.add_development_dependency 'database_cleaner', '~> 1.7'
32
+ spec.add_development_dependency 'combustion', '~> 1.0'
33
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module Imyou
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ desc "Generators migration for Imyou(imyous table)"
8
+
9
+ def self.orm
10
+ Rails::Generators.options[:rails][:orm]
11
+ end
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)))
15
+ end
16
+
17
+ def self.orm_has_migration?
18
+ [:active_record].include? orm
19
+ end
20
+
21
+ def self.next_migration_number(path)
22
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+ def create_migration_file
26
+ if self.class.orm_has_migration?
27
+ migration_template 'migration.rb', 'db/migrate/imyou_migration.rb', migration_version: migration_version
28
+ end
29
+ end
30
+
31
+ def migration_version
32
+ if rails5?
33
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
34
+ end
35
+ end
36
+
37
+ def rails5?
38
+ Rails.version.start_with? '5'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ class IMyouMigration < ActiveRecord::Migration<%= migration_version %>
2
+ def self.up
3
+ create_table :imyou_nicknames do |t|
4
+ t.references :model, polymorphic: true
5
+ t.string :name, null: false
6
+ t.timestamps
7
+ end
8
+ add_index :imyou_nicknames, :name
9
+ add_index :imyou_nicknames,
10
+ [ :name, :model_id, :model_type ],
11
+ unique: true,
12
+ name: 'imyou_unique_name'
13
+ end
14
+
15
+ def self.down
16
+ remove_index :imyou_nicknames, :name
17
+ remove_index :imyou_nicknames,
18
+ [ :name, :model_id, :model_type ],
19
+ name: 'imyou_unique_name'
20
+ drop_table :imyou_nicknames
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ require "imyou/version"
2
+ require 'active_record'
3
+ require 'active_support/inflector'
4
+
5
+ module Imyou
6
+ if defined?(ActiveRecord::Base)
7
+ require 'imyou/models'
8
+ require 'imyou/nickname'
9
+ ActiveRecord::Base.extend Imyou::Models
10
+ end
11
+ end
@@ -0,0 +1,54 @@
1
+ module Imyou
2
+ module Models
3
+ def has_imyou?
4
+ false
5
+ end
6
+
7
+ def has_imyou
8
+ class_eval do
9
+
10
+ has_many :imyou_nicknames, class_name: 'Imyou::Nickname', as: :model, dependent: :destroy
11
+ scope :with_nicknames, -> { eager_load(:imyou_nicknames) }
12
+
13
+ scope :match_by_nickname, ->(nickname) do
14
+ with_nicknames.merge(
15
+ Imyou::Nickname.where(Imyou::Nickname.arel_table[:name].eq(sanitize_sql_like(nickname)))
16
+ )
17
+ end
18
+
19
+ scope :partial_match_by_nickname, ->(nickname) do
20
+ with_nicknames.merge(
21
+ Imyou::Nickname.where(Imyou::Nickname.arel_table[:name].matches("%#{sanitize_sql_like(nickname)}%"))
22
+ )
23
+ end
24
+
25
+ def self.has_imyou?
26
+ true
27
+ end
28
+
29
+ def nicknames
30
+ self.imyou_nicknames.pluck(:name)
31
+ end
32
+
33
+ def remove_all_nicknames
34
+ self.imyou_nicknames.delete_all
35
+ end
36
+
37
+ def add_nickname(nickname)
38
+ self.imyou_nicknames.create!(name: nickname)
39
+ end
40
+
41
+ def remove_nickname(nickname)
42
+ self.imyou_nicknames.find_by(name: nickname)&.destroy!
43
+ end
44
+
45
+ def nicknames=(new_nicknames)
46
+ self.imyou_nicknames.where.not(name: new_nicknames).delete_all
47
+ new_nicknames.each do |new_nickname|
48
+ self.imyou_nicknames.find_or_create_by(name: new_nickname)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module Imyou
2
+ class Nickname < ::ActiveRecord::Base
3
+ self.table_name = 'imyou_nicknames'
4
+ belongs_to :model, polymorphic: true
5
+
6
+ scope :by_type, -> (klass) { where(model_type: klass.name) }
7
+ scope :default_order, -> { order(created_at: :asc) }
8
+ default_scope { default_order }
9
+
10
+ validates :model_id, presence: true
11
+ validates :model_type, presence: true
12
+ validates :name, presence: true
13
+ validates_uniqueness_of :name, scope: [ :model_id, :model_type ]
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Imyou
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imyou
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - patorash
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-14 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: combustion
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: Imyou has feature of attaching popular name to ActiveRecord model.
98
+ email:
99
+ - chariderpato@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - gemfiles/rails_4_2.gemfile
116
+ - gemfiles/rails_5_0.gemfile
117
+ - gemfiles/rails_5_1.gemfile
118
+ - gemfiles/rails_5_2.gemfile
119
+ - imyou.gemspec
120
+ - lib/generators/imyou/migration/migration_generator.rb
121
+ - lib/generators/imyou/migration/templates/active_record/migration.rb
122
+ - lib/imyou.rb
123
+ - lib/imyou/models.rb
124
+ - lib/imyou/nickname.rb
125
+ - lib/imyou/version.rb
126
+ homepage: https://github.com/patorash/imyou
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.7.6
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Imyou has feature of attaching popular name to ActiveRecord model.
150
+ test_files: []