confirmed_attributes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ef3e6159580e4a642a25b585404cd6f18cff237
4
+ data.tar.gz: f2d2d4db9414bf54ac1f2850c4419898964e1e4c
5
+ SHA512:
6
+ metadata.gz: fb5d1567f02b9aae8a086a25fc862ec37d4f055d431a45121b1a2b5d69527246ead7ecea1d7a2ef25e9b1ea937155262365bdad2a3e919c25fdd90bce0e41687
7
+ data.tar.gz: d0a49b80a2cc833074600833df5a9038c154240edbf7aa4894c3855b2a1188f6513564c55d60d0ec667bab5eff703dda06031db4b8726f206c9ef9df053edefd
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /dummy/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format doc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alexander
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.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # ConfirmedAttributes
2
+
3
+ Confirmed attributes for ActiveRecord.
4
+
5
+ Adds functionality confirmable attributes to models.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'confirmed_attributes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install confirmed_attributes
22
+
23
+ ## Usage
24
+
25
+ Add confirmable_attribute method to your model:
26
+
27
+ ```ruby
28
+ class User < ActiveRecord::Base
29
+ confirmable_attribute :email
30
+ end
31
+ ```
32
+
33
+ And use it:
34
+
35
+ ```ruby
36
+ @user = User.create email: "your_mail"
37
+
38
+ @user.confirmable_attributes # => [:email]
39
+ User.confirmable_attributes # => [:email]
40
+ @user.confimed_attributes # => []
41
+ @user.confirmed_attribute? :email # => false
42
+
43
+ @user.confirm :email
44
+ @user.confimed_attributes # => [#<ConfirmedAttributes::Control:0x007f2eacd2f730> name: "email", value: "your_mail"...]
45
+ @user.confirmed_attribute? :email # => true
46
+ ```
47
+
48
+ Simple, yeah?
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/confirmed_attributes/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "test_gem"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'confirmed_attributes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "confirmed_attributes"
8
+ spec.version = ConfirmedAttributes::VERSION
9
+ spec.authors = ["Alexander Shlinchak"]
10
+ spec.email = ["ashlinchak@gmail.com"]
11
+
12
+ spec.summary = %q{Confirmable attributes for ActiveRecord}
13
+ spec.description = %q{Adds functionality confirmable attributes to models.}
14
+ spec.homepage = "https://github.com/ashlinchak/confirmed_attributes"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3.0"
25
+ spec.add_development_dependency "sqlite3", "~> 1.3.10"
26
+ spec.add_development_dependency "activerecord", "~> 4.2.3"
27
+ end
@@ -0,0 +1,53 @@
1
+ module ConfirmedAttributes
2
+ module Confirmable
3
+
4
+ def attribute_confirmable?
5
+ false
6
+ end
7
+
8
+ def confirmable_attribute(*args)
9
+ cattr_accessor :confirmable_attributes
10
+ self.confirmable_attributes = args.map(&:to_sym)
11
+
12
+ include ConfirmedAttributes::Confirmable::ConfirmableMethods
13
+ end
14
+
15
+ module ConfirmableMethods
16
+ def self.included(klass)
17
+ klass.class_eval do
18
+ include ConfirmedAttributes::Confirmable::InstanceMethods
19
+
20
+ has_many :confirmed_attributes, as: :targetable, dependent: :delete_all, class_name: "ConfirmedAttributes::Control"
21
+
22
+ def self.attribute_confirmable?
23
+ true
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ module InstanceMethods
30
+ def confirmed_attribute?(attribute_name)
31
+ if confirmable_attribute? attribute_name
32
+ attribute = confirmed_attributes.find_by(name: attribute_name)
33
+ return false unless attribute
34
+
35
+ attribute && attribute.value.to_s == send(attribute_name).to_s
36
+ end
37
+ end
38
+
39
+ def confirm(attribute_name, user_id = nil)
40
+ return false if new_record? || send(attribute_name).blank?
41
+
42
+ confirmed_attribute = confirmed_attributes.new user_id: nil
43
+ confirmed_attribute.verify(attribute_name)
44
+ end
45
+
46
+ def confirmable_attribute?(attribute_name)
47
+ return false if attribute_name.blank?
48
+
49
+ confirmable_attributes.include? attribute_name.to_sym
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ module ConfirmedAttributes
2
+ class Control < ActiveRecord::Base
3
+ self.table_name_prefix = "confirmed_attributes_"
4
+
5
+ belongs_to :user
6
+ belongs_to :targetable, polymorphic: true
7
+
8
+ validates :name, :value, :targetable, presence: true
9
+
10
+ def title
11
+ "#{name}: #{value}"
12
+ end
13
+
14
+ def verify(attribute_name)
15
+ if targetable.confirmable_attribute?(attribute_name)
16
+ self.name = attribute_name.to_s
17
+ self.value = targetable.send(attribute_name).to_s
18
+ save
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ConfirmedAttributes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_record'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+
5
+ module ConfirmedAttributes
6
+ if defined?(ActiveRecord::Base)
7
+ require "confirmed_attributes/version"
8
+ require "confirmed_attributes/confirmable"
9
+ require "confirmed_attributes/control"
10
+
11
+ ActiveRecord::Base.extend ConfirmedAttributes::Confirmable
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class ConfirmedAttributes::InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def self.next_migration_number(path)
8
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
9
+ end
10
+
11
+ def generate_files
12
+ migration_template 'migration.rb', 'db/migrate/create_confirmed_attributes_tables.rb'
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ class CreateConfirmedAttributesTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :confirmed_attributes_controls do |t|
4
+ t.string :name, null: false, limit: 64
5
+ t.text :value, null: false
6
+ t.references :targetable, polymorphic: true, null: false
7
+ t.references :user
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :confirmed_attributes_controls, :name
13
+ add_index :confirmed_attributes_controls, :user_id
14
+ add_index :confirmed_attributes_controls, :targetable_id
15
+ add_index :confirmed_attributes_controls, :targetable_type
16
+ end
17
+
18
+ def self.down
19
+ drop_table :confirmed_attributes
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confirmed_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Shlinchak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-12 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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.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.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.10
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.2.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.3
83
+ description: Adds functionality confirmable attributes to models.
84
+ email:
85
+ - ashlinchak@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - confirmed_attributes.gemspec
101
+ - lib/confirmed_attributes.rb
102
+ - lib/confirmed_attributes/confirmable.rb
103
+ - lib/confirmed_attributes/control.rb
104
+ - lib/confirmed_attributes/version.rb
105
+ - lib/generators/confirmed_attributes/install_generator.rb
106
+ - lib/generators/confirmed_attributes/templates/migration.rb
107
+ homepage: https://github.com/ashlinchak/confirmed_attributes
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Confirmable attributes for ActiveRecord
131
+ test_files: []