looker 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -7
- data/lib/looker.rb +2 -2
- data/lib/looker/table.rb +6 -6
- data/lib/looker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a5342e20caa742f53a0942966eb4817997e2da5
|
4
|
+
data.tar.gz: 7847fcfa2255e1ab7bdcd79dd8a19337f30dbafb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 442db2eae4c325720af442d14a741fede185810b512b8e148fe7d1febaf6267174e936569dc452685f3b7cfa703b7e130f1ff88ac29238a8f2f56a324fcd298f
|
7
|
+
data.tar.gz: ccf69f7eed81d36b3d5295d7a85069e218768faf07b549428180ed34aaeeb817973ee425ec7af79d4fade12fc480f21d4e8a2fae96c579b8efc7d8277e25abf3
|
data/README.md
CHANGED
@@ -25,17 +25,23 @@ Looker.add roles: {
|
|
25
25
|
# The name (first Hash key) & value is converted
|
26
26
|
# to an upcase named frozen constant on the Looker module
|
27
27
|
|
28
|
-
Looker::ROLES[:admin]
|
29
|
-
Looker::ROLES[
|
28
|
+
Looker::ROLES[:admin] # => 1
|
29
|
+
Looker::ROLES["admin"] # => 1
|
30
|
+
Looker::ROLES[1] # => :admin
|
30
31
|
|
31
|
-
Looker::ROLES[:reader]
|
32
|
-
Looker::ROLES[
|
32
|
+
Looker::ROLES[:reader] # => 2
|
33
|
+
Looker::ROLES["reader"] # => 2
|
34
|
+
Looker::ROLES[2] # => :reader
|
33
35
|
|
36
|
+
Looker::ROLES[:writer] # => 3
|
34
37
|
Looker::ROLES["writer"] # => 3
|
35
|
-
Looker::ROLES[3]
|
36
|
-
|
38
|
+
Looker::ROLES[3] # => :writer
|
39
|
+
|
40
|
+
Looker::ROLES.name # => "roles"
|
41
|
+
Looker::ROLES.constant_name # => "ROLES"
|
37
42
|
|
38
|
-
|
43
|
+
Looker::ROLES.to_h # => {:admin=>1, :reader=>2, :writer=>3}
|
44
|
+
```
|
39
45
|
|
40
46
|
## Multiple Enumerated Types
|
41
47
|
|
data/lib/looker.rb
CHANGED
@@ -9,8 +9,8 @@ module Looker
|
|
9
9
|
def_delegators :@tables, :each
|
10
10
|
|
11
11
|
def add(data={})
|
12
|
-
data.each do |name,
|
13
|
-
table = Looker::Table.new(name,
|
12
|
+
data.each do |name, entries|
|
13
|
+
table = Looker::Table.new(name, entries)
|
14
14
|
if Looker.const_defined?(table.constant_name)
|
15
15
|
message = "Looker::#{table.constant_name} is already defined!"
|
16
16
|
raise ArgumentError.new(message)
|
data/lib/looker/table.rb
CHANGED
@@ -4,18 +4,18 @@ module Looker
|
|
4
4
|
class Table
|
5
5
|
extend Forwardable
|
6
6
|
include Enumerable
|
7
|
-
def_delegators :
|
8
|
-
attr_reader :name, :constant_name, :
|
7
|
+
def_delegators :entries, :each
|
8
|
+
attr_reader :name, :constant_name, :entries
|
9
9
|
|
10
10
|
def self.constant_name(name)
|
11
11
|
name.gsub(/\s/, "_").gsub(/\W/, "").upcase
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(name,
|
14
|
+
def initialize(name, entries={})
|
15
15
|
@name = name.to_s.strip.freeze
|
16
16
|
@constant_name = self.class.constant_name(@name).freeze
|
17
|
-
@
|
18
|
-
@dict =
|
17
|
+
@entries = entries.dup.freeze
|
18
|
+
@dict = entries.invert.merge(entries).freeze
|
19
19
|
freeze
|
20
20
|
end
|
21
21
|
|
@@ -24,7 +24,7 @@ module Looker
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_h
|
27
|
-
|
27
|
+
entries
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
data/lib/looker/version.rb
CHANGED