activerecord-hideable 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f8a0667c74c05d54b411feddac8e658d5079b80
4
+ data.tar.gz: 81a9072e73726b74413cbd5a7f449f4a3e992cbf
5
+ SHA512:
6
+ metadata.gz: 6da0baa99af42e40cf4f7fe03641a381bf2ae1be553c3a4147e6d79b82e5622f1520356c4245f25b6fb17a14d377846637d8ff332c361edd582e0a48c3e8ee0f
7
+ data.tar.gz: a26a1165b29ddd4ded55495ed75b9e717de7705b1e35c9c460ed1af1eda77a288e66c202fd9c359549f6c55f01b8651291d1f6340d580425e3e67753397e1bc6
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yaroslav Konoplov
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.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ ```ruby
2
+ class Article < ActiveRecord::Base
3
+ acts_as_hideable
4
+ end
5
+
6
+ Article.shown # => Returns collection of articles with hidden => false
7
+ Article.features.hideable? # => true
8
+ Article.attribute_features[:hidden].hideable_toggle? # => true
9
+ ```
10
+
11
+ ## Gemfile
12
+ ```ruby
13
+ gem 'activerecord-hideable', '~> 1.0'
14
+ ```
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'activerecord-hideable'
6
+ s.version = '1.0.1'
7
+ s.authors = ['Yaroslav Konoplov']
8
+ s.email = ['eahome00@gmail.com']
9
+ s.summary = 'Toggles for ActiveRecord models'
10
+ s.description = 'Toggles for ActiveRecord models'
11
+ s.homepage = 'http://github.com/yivo/activerecord-hideable'
12
+ s.license = 'MIT'
13
+
14
+ s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_dependency 'activesupport', '>= 3.0', '< 6.0'
20
+ s.add_dependency 'activerecord', '>= 3.0', '< 6.0'
21
+ s.add_dependency 'activerecord-traits', '~> 1.0'
22
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Essay
5
+ class ModelFeatures
6
+ def hideable?
7
+ model_class.respond_to?(:hideable_options)
8
+ end
9
+
10
+ serialize do
11
+ { is_hideable: hideable? }
12
+ end
13
+ end
14
+
15
+ class AttributeFeatures
16
+ def toggle?
17
+ model_features.hideable? && model_class.hideable_options.fetch(:toggle) == attribute_name
18
+ end
19
+
20
+ serialize do
21
+ { is_toggle: toggle? }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Hideable
5
+ module Macro
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ #
10
+ # class Article < ActiveRecord::Base
11
+ # acts_as_hideable toggle: :hidden
12
+ # end
13
+ #
14
+ def acts_as_hideable(options = {})
15
+ options.reverse_merge!(toggle: Hideable.default_column)
16
+ toggle = options[:toggle]
17
+
18
+ scope :hidden, -> { where(toggle => true) }
19
+ scope :shown, -> { where(toggle => false) }
20
+
21
+ define_method(:shown?) { !self[toggle] }
22
+ define_method(:hidden?) { !!self[toggle] } unless toggle == :hidden
23
+
24
+ unless respond_to?(:hideable_options)
25
+ class_attribute :hideable_options, instance_accessor: false, instance_predicate: false
26
+ end
27
+
28
+ self.hideable_options = options
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Hideable
5
+ module Migration
6
+ def toggle(column_name = Hideable.default_column, **options)
7
+ options.reverse_merge!(null: false, default: false, index: true)
8
+ column(column_name, :boolean, options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'active_support/concern'
5
+ require 'active_record'
6
+ require 'activerecord-traits'
7
+
8
+ require 'activerecord-hideable/macro'
9
+ require 'activerecord-hideable/column_types'
10
+
11
+ begin
12
+ require 'essay'
13
+ require 'activerecord-hideable/essay'
14
+ rescue LoadError
15
+ end
16
+
17
+ module Hideable
18
+ class << self
19
+ attr_accessor :default_column
20
+ end
21
+
22
+ self.default_column = :hidden
23
+ end
24
+
25
+ class ActiveRecord::Base
26
+ include Hideable::Macro
27
+ end
28
+
29
+ class ActiveRecord::ConnectionAdapters::TableDefinition
30
+ include Hideable::Migration
31
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-hideable
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: activerecord-traits
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.0'
67
+ description: Toggles for ActiveRecord models
68
+ email:
69
+ - eahome00@gmail.com
70
+ executables: []
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - ".gitignore"
75
+ - LICENSE.txt
76
+ - README.md
77
+ - activerecord-hideable.gemspec
78
+ - lib/activerecord-hideable.rb
79
+ - lib/activerecord-hideable/essay.rb
80
+ - lib/activerecord-hideable/macro.rb
81
+ - lib/activerecord-hideable/migration.rb
82
+ homepage: http://github.com/yivo/activerecord-hideable
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.5.1
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Toggles for ActiveRecord models
106
+ test_files: []