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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dad7e20ae350e0e54f884e2fca05f59004d428968fe8c657d59000058f6e9cc
4
- data.tar.gz: d7fa448bdcf15b765b931665ba80eaf0cc58d31efba04caf4ccff89cde17c872
3
+ metadata.gz: 05b629e83f5630a4d6da8a48c845ad5f33ae948843032af48f99b0d3ca491ae5
4
+ data.tar.gz: ec63cf2af40ea0a1a32e7c47fc2d9cad4808f670b1db27dddaeea33e2e3eb570
5
5
  SHA512:
6
- metadata.gz: e8d1b8afa60670037d4c7f3b37de22cf750ee90e49284abea6b3758f20d21a1ebe249729538d4dd6951026250b9af625d689900928f66c5b9885214e525bb689
7
- data.tar.gz: f5db473feff15d8f9bd0c1008edf0041b0f0d459d2ad0c8ddbb5b3ebd6e44386f8e5dab5204033a3cc4c3a9698a152e8fd2b122c6ff657159b045ca5ffa81ab7
6
+ metadata.gz: f8cd06f0009f6411ff914006b1ff0bd931f334666f7585dc411a851cf502a51e5792630c64c0464976c7f06ff99b1c93d0871daf799f906bf4d55ad7b3f599bf
7
+ data.tar.gz: 6aadb812f22f6d48d869ab6cc4027939c9598cefcefb1d84c5c8e1d1eb0f3b48f486dbf73816dabee04586c75ab9dc00d8278cf5e0fa604e3d34908a5242f1ef
data/lib/tablesalt.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
+ require "short_circu_it"
4
5
 
5
6
  require "tablesalt/version"
6
7
 
7
- require "tablesalt/array_index"
8
- require "tablesalt/hash_model"
8
+ require "tablesalt/stringable_object"
9
9
 
10
10
  module Tablesalt; end
@@ -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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tablesalt
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.9.5"
5
+ VERSION = "0.10.0"
6
6
  end
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.9.5
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-20 00:00:00.000000000 Z
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/array_index.rb
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
@@ -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