RubyHstoreMgmt 0.1.0 → 0.1.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 +4 -4
- data/.gitattributes +2 -0
- data/.idea/.gitignore +8 -0
- data/.idea/RubyRoles.iml +43 -0
- data/.idea/aws.xml +11 -0
- data/.idea/inspectionProfiles/Project_Default.xml +17 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +7 -0
- data/README.md +46 -0
- data/Rakefile +4 -0
- data/lib/RubyHstoreMgmt.rb +21 -0
- data/lib/ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/class_methods.rb +14 -0
- data/lib/ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/instance_methods.rb +10 -0
- data/lib/ruby_hstore_mgmt/concerns/hstore_mgmt.rb +85 -0
- data/lib/ruby_hstore_mgmt/version.rb +5 -0
- data/sig/RubyHstoreMgmt.rbs +4 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd009b1469575bfd3eea2d259cab8a1ffa4ed4280e3121f9edfe5d93c524ffa
|
4
|
+
data.tar.gz: c8074196cb835b6a59d73ba6454aed4c29532a69c58f4684baf6637089cc1863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff022ef0c216b57f42f2f64bccdb4a8bc5b92dcefb6c8d4afebf27a503dc9624fb4ebce89db4302249ef0f35bd10803db399e7aae46c93b867293ffc2b2b1c84
|
7
|
+
data.tar.gz: '088e97166627d07a642711795b698fa448d07dd7f37f920268ce1924bdde7a0c0c2ccb1dbfe8a98169533263d8813d58d4a06553f2ac01c64ff04f4b9078a374'
|
data/.gitattributes
ADDED
data/.idea/.gitignore
ADDED
data/.idea/RubyRoles.iml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="activemodel (v8.0.2, ruby-3.2.2-p53) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord (v8.0.2, ruby-3.2.2-p53) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v8.0.2, ruby-3.2.2-p53) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="base64 (v0.3.0, ruby-3.2.2-p53) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="benchmark (v0.4.1, ruby-3.2.2-p53) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.2.2, ruby-3.2.2-p53) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.7.1, ruby-3.2.2-p53) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.3.5, ruby-3.2.2-p53) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.5.3, ruby-3.2.2-p53) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="date (v3.4.1, ruby-3.2.2-p53) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="drb (v2.2.3, ruby-3.2.2-p53) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="erb (v5.0.2, ruby-3.2.2-p53) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.7, ruby-3.2.2-p53) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.1, ruby-3.2.2-p53) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="irb (v1.15.2, ruby-3.2.2-p53) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="logger (v1.7.0, ruby-3.2.2-p53) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.5, ruby-3.2.2-p53) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, ruby-3.2.2-p53) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, ruby-3.2.2-p53) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="psych (v5.2.6, ruby-3.2.2-p53) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.3.0, ruby-3.2.2-p53) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rdoc (v6.14.2, ruby-3.2.2-p53) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="reline (v0.6.2, ruby-3.2.2-p53) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="securerandom (v0.4.1, ruby-3.2.2-p53) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="stringio (v3.1.7, ruby-3.2.2-p53) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="timeout (v0.4.3, ruby-3.2.2-p53) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, ruby-3.2.2-p53) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="uri (v1.0.3, ruby-3.2.2-p53) [gem]" level="application" />
|
42
|
+
</component>
|
43
|
+
</module>
|
data/.idea/aws.xml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="accountSettings">
|
4
|
+
<option name="activeRegion" value="us-east-1" />
|
5
|
+
<option name="recentlyUsedRegions">
|
6
|
+
<list>
|
7
|
+
<option value="us-east-1" />
|
8
|
+
</list>
|
9
|
+
</option>
|
10
|
+
</component>
|
11
|
+
</project>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
2
|
+
<profile version="1.0">
|
3
|
+
<option name="myName" value="Project Default" />
|
4
|
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5
|
+
<option name="ignoredPackages">
|
6
|
+
<value>
|
7
|
+
<list size="4">
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="pulumi_awsx" />
|
9
|
+
<item index="1" class="java.lang.String" itemvalue="pulumi_nuage" />
|
10
|
+
<item index="2" class="java.lang.String" itemvalue="pulumi-aws" />
|
11
|
+
<item index="3" class="java.lang.String" itemvalue="pulumi" />
|
12
|
+
</list>
|
13
|
+
</value>
|
14
|
+
</option>
|
15
|
+
</inspection_tool>
|
16
|
+
</profile>
|
17
|
+
</component>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/RubyRoles.iml" filepath="$PROJECT_DIR$/.idea/RubyRoles.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# RubyHstoreMgmt
|
2
|
+
|
3
|
+
Assign roles to users, accounts, user_accounts, and other models in a Ruby on Rails application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add RubyHstoreMgmt
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install RubyHstoreMgmt
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TBD
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class MyModel < ApplicationRecord
|
25
|
+
acts_as_ruby_hstore_mgmt
|
26
|
+
xxx
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/leeatchison/RubyHstoreMgmt.
|
40
|
+
|
41
|
+
To build a new gem (authorized deployers only can do the push):
|
42
|
+
|
43
|
+
```bash
|
44
|
+
gem build RubyHstoreMgmt.gemspec
|
45
|
+
gem push RubyHstoreMgmt-#.#.#.gem
|
46
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'active_support/concern'
|
6
|
+
require "ruby_hstore_mgmt/version"
|
7
|
+
require "ruby_hstore_mgmt/concerns/hstore_mgmt"
|
8
|
+
require "ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/instance_methods"
|
9
|
+
require "ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/class_methods"
|
10
|
+
|
11
|
+
module RubyHstoreMgmt
|
12
|
+
class Error < StandardError; end
|
13
|
+
|
14
|
+
class Railtie < Rails::Railtie
|
15
|
+
initializer 'RubyHstoreMgmt.acts_as_ruby_hstore_mgmt' do
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
17
|
+
ActiveRecord::Base.extend RubyHstoreMgmt::ActsAsRubyHstoreMgmt::ClassMethods
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# lib/ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/class_methods.rb
|
2
|
+
module RubyHstoreMgmt
|
3
|
+
module ActsAsRubyHstoreMgmt
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
module ClassMethods
|
6
|
+
def acts_as_ruby_hstore_mgmt(options = {})
|
7
|
+
include RubyHstoreMgmt::ActsAsRubyHstoreMgmt::InstanceMethods
|
8
|
+
include RubyHstoreMgmt::Concerns::HstoreMgmt
|
9
|
+
# Initialize the class instance variables
|
10
|
+
@roles_field_name = options[:field_name] if options[:field_name].present?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# Usage:
|
3
|
+
# In model:
|
4
|
+
# include HstoreMgmt
|
5
|
+
# hstore_accessor :hstore_column_name, :attr1, :attr2, :attr3
|
6
|
+
# hstore_bool_accessor :hstore_column_name, :attr1, :attr2, :attr3
|
7
|
+
# hstore_json_accessor :hstore_column_name, :attr1, :attr2, :attr3
|
8
|
+
# (any of the above hstore_*accessor lines)
|
9
|
+
# In controller's model_params method:
|
10
|
+
# params.require(:model).permit(Model.hstore_permits(:hstore_column_name,:other,:model,:attributes))
|
11
|
+
# or:
|
12
|
+
# params.expect(model:Model.hstore_permits(:hstore_column_name,:other,:model,:attributes))
|
13
|
+
#
|
14
|
+
module RubyHstoreMgmt
|
15
|
+
module Concerns
|
16
|
+
module HstoreMgmt
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
included do
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# Generic HSTORE
|
22
|
+
#
|
23
|
+
#
|
24
|
+
def self.hstore_accessor column, *attrs
|
25
|
+
attrs = [ attrs ].flatten
|
26
|
+
@hstore_accessor_list||={}
|
27
|
+
@hstore_accessor_list[column.to_sym]||=[]
|
28
|
+
@hstore_accessor_list[column.to_sym]+=attrs
|
29
|
+
assign_column="#{column}="
|
30
|
+
attrs.each do |attr|
|
31
|
+
self.define_method attr do
|
32
|
+
self.send(column)[attr.to_s].to_s
|
33
|
+
end
|
34
|
+
self.define_method "#{attr}=" do |val|
|
35
|
+
self.send(column)[attr.to_s]=val.to_s
|
36
|
+
end
|
37
|
+
self.define_method "#{attr}?" do
|
38
|
+
self.send(column)[attr.to_s].present?
|
39
|
+
end
|
40
|
+
self.define_method "clear_#{attr}" do
|
41
|
+
self.send(column)[attr.to_s]=nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def self.hstore_bool_accessor column, *attrs
|
46
|
+
self.hstore_accessor column, *attrs
|
47
|
+
assign_column="#{column}="
|
48
|
+
[ attrs ].flatten.each do |attr|
|
49
|
+
self.define_method "#{attr}_bool" do
|
50
|
+
self.send(column)[attr.to_s].to_i != 0
|
51
|
+
end
|
52
|
+
self.define_method "#{attr}_bool=" do |val|
|
53
|
+
self.send(column)[attr.to_s]= (!!val) ? "1" : "0"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
def self.hstore_json_accessor column, *attrs
|
58
|
+
self.hstore_accessor column, *attrs
|
59
|
+
assign_column="#{column}="
|
60
|
+
[ attrs ].flatten.each do |attr|
|
61
|
+
self.define_method "#{attr}_json" do
|
62
|
+
return {} unless self.send(column)[attr.to_s].present?
|
63
|
+
JSON.parse(self.send(column)[attr.to_s].to_s)
|
64
|
+
end
|
65
|
+
self.define_method "#{attr}_json=" do |val|
|
66
|
+
self.send(column)[attr.to_s]=val.to_json
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def self.hstore_attrs_list(column)
|
71
|
+
@hstore_accessor_list||={}
|
72
|
+
@hstore_accessor_list[column.to_sym]||=[]
|
73
|
+
@hstore_accessor_list[column.to_sym]
|
74
|
+
end
|
75
|
+
def self.hstore_permits columns_array, *attrs
|
76
|
+
res = attrs
|
77
|
+
[ columns_array ].flatten.each do |col|
|
78
|
+
res+=self.hstore_attrs_list(col)
|
79
|
+
end
|
80
|
+
res
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubyHstoreMgmt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Atchison
|
@@ -45,7 +45,23 @@ email:
|
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
|
-
files:
|
48
|
+
files:
|
49
|
+
- ".gitattributes"
|
50
|
+
- ".idea/.gitignore"
|
51
|
+
- ".idea/RubyRoles.iml"
|
52
|
+
- ".idea/aws.xml"
|
53
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
54
|
+
- ".idea/misc.xml"
|
55
|
+
- ".idea/modules.xml"
|
56
|
+
- ".idea/vcs.xml"
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/RubyHstoreMgmt.rb
|
60
|
+
- lib/ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/class_methods.rb
|
61
|
+
- lib/ruby_hstore_mgmt/acts_as_ruby_hstore_mgmt/instance_methods.rb
|
62
|
+
- lib/ruby_hstore_mgmt/concerns/hstore_mgmt.rb
|
63
|
+
- lib/ruby_hstore_mgmt/version.rb
|
64
|
+
- sig/RubyHstoreMgmt.rbs
|
49
65
|
homepage: https://github.com/leeatchison/RubyHstoreMgmt
|
50
66
|
licenses: []
|
51
67
|
metadata:
|