columns-roles 0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +0 -0
  3. data/lib/columns-roles.rb +55 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f6ddb64b10e17851c2ba308e8d7f02af328c29a
4
+ data.tar.gz: 84f7c01d8f4fb7870646f2b3ba8d8e47c66a27a6
5
+ SHA512:
6
+ metadata.gz: aaac512c88caed0b6628e5fb6ed29b0cd7556aabdf4922d93a28c82c117ace0ec40a565c107b3b376a9c89549cad7abc5196fc06ae0654a5347767a23a04a959
7
+ data.tar.gz: a776a59e78e43d2b3d0bbc626c9c45bd5630f01538850ffae9b0ac57a1a79ef70c5afdbf584ca6ca63ab6daf4c6472cf74eb62ac35971982562a35acc2d40d05
File without changes
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ module ColumnsRoles
3
+ module Base
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def columns_roles(column, options={})
8
+ roles = options[:roles]
9
+
10
+ class_eval %(
11
+ def roles=(roles)
12
+ self.#{column} = (#{roles} & roles).map { |role|
13
+ 2 ** #{roles}.index(role.to_sym)
14
+ }.sum
15
+ end
16
+
17
+ def roles
18
+ #{roles}.reject { |role|
19
+ ((#{column} || 0 ) & 2 ** #{roles}.index(role.to_sym)).zero?
20
+ }
21
+ end
22
+
23
+ def role?(role)
24
+ self.roles.include? role.to_sym
25
+ end
26
+
27
+ def role
28
+ self.roles[0]
29
+ end
30
+
31
+ def role=(role)
32
+ self.roles = (#{roles} & [role.to_sym])
33
+ end
34
+
35
+ def set_role(role)
36
+ self.role = role
37
+ end
38
+
39
+ scope :with_role, lambda{ |role|
40
+ {
41
+ :conditions => ['#{column} & ? > 0', 2 ** #{roles}.index(role.to_sym)]
42
+ }
43
+ }
44
+ )
45
+ roles.each{ |role|
46
+ define_method "is_#{role}?" do
47
+ role? role
48
+ end
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ ActiveRecord::Base.send :include, ColumnsRoles::Base
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: columns-roles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - topmi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Table add roles at column
14
+ email: github163@163.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/columns-roles.rb
20
+ - README.md
21
+ homepage: http://rubygems.org/gems/columns-roles
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: table in column add roles
45
+ test_files: []