tablesalt 0.15.2 → 0.16.1

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: 3df9e0eb5e4009ccbbac25a7cae389d637139b135ca13ed076e7bc3973de32b0
4
- data.tar.gz: 43f4b8bd94e93c2d1306329524b0c78baaff31e318c20d25de6c6140dba9133c
3
+ metadata.gz: 38cb1caef71ccc010336089b892a54e78d114f989d03bab88d55d46fc1abb73b
4
+ data.tar.gz: 43b16a4898303a3e134963b2b8418132cf2ceb6c840e617fef32ad1deab13173
5
5
  SHA512:
6
- metadata.gz: 7784e49f4ca14a5893830024b5b423fafd6f599ded7e24bbfda1ec7d964670b98abf30d35862c995bd1fe523007f275ec2b3a13dc68c9515af943ea7df45ee6f
7
- data.tar.gz: 4fa17eb2c65cd7aca1f6b164ba23e5ad370f038cddf3b27ba04fa167bd4bf23899bdb8df3f974c21332ee042197afae84cd60ab2dfaaf3b3d1de2fc32e0008d9
6
+ metadata.gz: '09bff68945b1efd6b2abfa73a7f0b0a7cb1931a5ce8bdeba1c19ce1a186ba54671e6ad5b8613109b909c0f836fb4148cea59fe4c454e69790ee6e5193a4eec33'
7
+ data.tar.gz: 986492f9a62364b9eb6e8a18ece9842e3f72945202557db6de6ef31dfeeb02afb4c72c23572c08511629dabb092eae70098aecffad2631268337b198ae52007a
@@ -5,6 +5,7 @@ require "short_circu_it"
5
5
 
6
6
  require "tablesalt/version"
7
7
 
8
+ require "tablesalt/dsl_accessor"
8
9
  require "tablesalt/stringable_object"
9
10
  require "tablesalt/uses_hash_for_equality"
10
11
 
@@ -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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tablesalt
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.15.2"
5
+ VERSION = "0.16.1"
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.15.2
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-15 00:00:00.000000000 Z
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