tablesalt 0.9.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tablesalt.rb +2 -2
- data/lib/tablesalt/stringable_object.rb +39 -0
- data/lib/tablesalt/version.rb +1 -1
- metadata +3 -4
- data/lib/tablesalt/array_index.rb +0 -29
- data/lib/tablesalt/hash_model.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b629e83f5630a4d6da8a48c845ad5f33ae948843032af48f99b0d3ca491ae5
|
4
|
+
data.tar.gz: ec63cf2af40ea0a1a32e7c47fc2d9cad4808f670b1db27dddaeea33e2e3eb570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8cd06f0009f6411ff914006b1ff0bd931f334666f7585dc411a851cf502a51e5792630c64c0464976c7f06ff99b1c93d0871daf799f906bf4d55ad7b3f599bf
|
7
|
+
data.tar.gz: 6aadb812f22f6d48d869ab6cc4027939c9598cefcefb1d84c5c8e1d1eb0f3b48f486dbf73816dabee04586c75ab9dc00d8278cf5e0fa604e3d34908a5242f1ef
|
data/lib/tablesalt.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tablesalt
|
4
|
+
module StringableObject
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
string_for(__method__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
string_for(__method__)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def stringable_attributes
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def string_for(method)
|
22
|
+
"#<#{self.class.name}#{" #{attribute_string(method)}" unless stringable_attributes.empty?}>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def attribute_string(method)
|
26
|
+
stringable_attribute_values.map { |attribute, value| "#{attribute}=#{value.public_send(method)}" }.join(" ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def stringable_attribute_values
|
30
|
+
stringable_attributes.each_with_object({}) { |attribute, result| result[attribute] = safe_send(attribute) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def safe_send(method)
|
34
|
+
public_send(method)
|
35
|
+
rescue StandardError
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/tablesalt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablesalt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Minneti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -49,8 +49,7 @@ files:
|
|
49
49
|
- LICENSE.txt
|
50
50
|
- README.md
|
51
51
|
- lib/tablesalt.rb
|
52
|
-
- lib/tablesalt/
|
53
|
-
- lib/tablesalt/hash_model.rb
|
52
|
+
- lib/tablesalt/stringable_object.rb
|
54
53
|
- lib/tablesalt/version.rb
|
55
54
|
homepage: https://github.com/Freshly/spicerack/tree/master/tablesalt
|
56
55
|
licenses:
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tablesalt
|
4
|
-
class ArrayIndex
|
5
|
-
class << self
|
6
|
-
alias_method :[], :new
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :array
|
10
|
-
|
11
|
-
delegate :[], to: :index
|
12
|
-
|
13
|
-
def initialize(array)
|
14
|
-
@array = array.deep_dup
|
15
|
-
end
|
16
|
-
|
17
|
-
def index
|
18
|
-
@index ||= array.each_with_index.each_with_object({}) do |(element, index), hash|
|
19
|
-
hash[element] = index unless hash.key?(element)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def freeze
|
24
|
-
index.freeze
|
25
|
-
array.freeze
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/tablesalt/hash_model.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_model"
|
4
|
-
|
5
|
-
module Tablesalt
|
6
|
-
module HashModel
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
include ActiveModel::Attributes
|
11
|
-
|
12
|
-
class_attribute :_fields, instance_writer: false, default: []
|
13
|
-
|
14
|
-
attr_accessor :hash
|
15
|
-
end
|
16
|
-
|
17
|
-
class_methods do
|
18
|
-
def inherited(base)
|
19
|
-
base._fields = _fields.dup
|
20
|
-
super
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def field(name, type = Type::Value.new, **options)
|
26
|
-
_fields << name
|
27
|
-
attribute(name, type, **options)
|
28
|
-
define_field_methods(name)
|
29
|
-
end
|
30
|
-
|
31
|
-
def define_field_methods(name)
|
32
|
-
define_method("#{name}=".to_sym) { |value| hash[name] = value }
|
33
|
-
define_method(name) do
|
34
|
-
write_attribute(name, hash[name] || attribute(name))
|
35
|
-
attribute(name)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|