tablesalt 0.15.2 → 0.16.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/lib/tablesalt.rb +1 -0
- data/lib/tablesalt/dsl_accessor.rb +69 -0
- data/lib/tablesalt/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38cb1caef71ccc010336089b892a54e78d114f989d03bab88d55d46fc1abb73b
|
4
|
+
data.tar.gz: 43b16a4898303a3e134963b2b8418132cf2ceb6c840e617fef32ad1deab13173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09bff68945b1efd6b2abfa73a7f0b0a7cb1931a5ce8bdeba1c19ce1a186ba54671e6ad5b8613109b909c0f836fb4148cea59fe4c454e69790ee6e5193a4eec33'
|
7
|
+
data.tar.gz: 986492f9a62364b9eb6e8a18ece9842e3f72945202557db6de6ef31dfeeb02afb4c72c23572c08511629dabb092eae70098aecffad2631268337b198ae52007a
|
data/lib/tablesalt.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/attr_internal"
|
4
|
+
|
5
|
+
# Utility for creating DSL class variables - great for base classes with many child classes.
|
6
|
+
#
|
7
|
+
# class Vehicle
|
8
|
+
# include Tablesalt::DSLAccessor
|
9
|
+
#
|
10
|
+
# dsl_accessor :this_many_wheels
|
11
|
+
#
|
12
|
+
# def self.inspect
|
13
|
+
# "I have #{this_many_wheels} wheels"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# class Car < Vehicle
|
18
|
+
# this_many_wheels 4
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# class Motorcycle < Vehicle
|
22
|
+
# this_many_wheels 2
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# class Semi < Vehicle
|
26
|
+
# this_many_wheels 18
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Car.inspect
|
30
|
+
# => "I have 4 wheels"
|
31
|
+
#
|
32
|
+
# Motorcycle.inspect
|
33
|
+
# => "I have 2 wheels"
|
34
|
+
#
|
35
|
+
# Semi.inspect
|
36
|
+
# => "I have 18 wheels"
|
37
|
+
#
|
38
|
+
module Tablesalt
|
39
|
+
module DSLAccessor
|
40
|
+
extend ActiveSupport::Concern
|
41
|
+
|
42
|
+
class_methods do
|
43
|
+
private
|
44
|
+
|
45
|
+
def dsl_accessor(*accessors)
|
46
|
+
accessors.each { |attr| _define_dsl_accessor(attr) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def _define_dsl_accessor(attr)
|
50
|
+
define_singleton_method attr do |*args|
|
51
|
+
ivar_name = attr_internal_ivar_name(attr)
|
52
|
+
|
53
|
+
if instance_variable_defined?(ivar_name)
|
54
|
+
raise NameError, "internal attribute #{attr} already set" if args.one?
|
55
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" if args.size > 1
|
56
|
+
|
57
|
+
instance_variable_get(ivar_name)
|
58
|
+
else
|
59
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)" unless args.one?
|
60
|
+
|
61
|
+
instance_variable_set(ivar_name, args.first)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private_class_method attr
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
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.16.1
|
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-08-
|
11
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- LICENSE.txt
|
50
50
|
- README.md
|
51
51
|
- lib/tablesalt.rb
|
52
|
+
- lib/tablesalt/dsl_accessor.rb
|
52
53
|
- lib/tablesalt/stringable_object.rb
|
53
54
|
- lib/tablesalt/uses_hash_for_equality.rb
|
54
55
|
- lib/tablesalt/version.rb
|