tablesalt 0.10.1 → 0.10.2

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: b16d829b29d589e9b09308f244ca850e8571ab98c599683767bf801afa4d3662
4
- data.tar.gz: 4ed2564107099613460dcd57ccbb33062f89fe810bbcaa73c310630cf699f029
3
+ metadata.gz: a7b0424fb3fc3453959d0d62bcb685dbe6fd58b95683cf74b6ce3138fd7ac4d1
4
+ data.tar.gz: 5937fe4f663ef07913e65d35b0f6d9b256a5fec554eef0c7561b638edc28af7b
5
5
  SHA512:
6
- metadata.gz: 7353cafb6af9b6113afe8461a14500c5f235480eec09944ce993eb5035dad794ad65496729ddfae6d5433b27c571de02938f8094b72da1b4f74da2fa611c8e9a
7
- data.tar.gz: 100534a66695eb7a111088a46ac5d8e4904104912a5acaed6031f149448f0417d0973e6491732fda0152577b6c749c85598b44157d4396d592031784deaf7e41
6
+ metadata.gz: 8729233e2e6b92e8f6fb91231be61806d8809ba6b8cdcf214ea5889bc061b24bdd82715110f0463d49cfe128c1dacc9caca6ad4e8be0955613484caeab8d3033
7
+ data.tar.gz: 39cce85dbf06863842cf9e6468f849d7729f2badf0baedda8b7c53cb174cd0f79d2eb186f29efe819e9f884dc715cbabc6e7015e620efcb75cedee24f4ea2f54
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defaults allow for storing values to use when none are specified by the developer.
4
+ module Tablesalt
5
+ module Dsl
6
+ module Defaults
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class_attribute :_defaults, instance_writer: false, default: {}
11
+ end
12
+
13
+ class_methods do
14
+ def inherited(base)
15
+ dup = _defaults.dup
16
+ base._defaults = dup.each { |k, v| dup[k] = v.dup }
17
+ super
18
+ end
19
+
20
+ private
21
+
22
+ def define_default(attribute, static: nil, &block)
23
+ _defaults[attribute] = Value.new(static: static, &block)
24
+ end
25
+ end
26
+
27
+ class Value
28
+ def initialize(static: nil, &block)
29
+ @value = (static.nil? && block_given?) ? block : static
30
+ end
31
+
32
+ def value
33
+ (@value.respond_to?(:call) ? instance_eval(&@value) : @value).dup
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Tablesalt
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.10.1"
5
+ VERSION = "0.10.2"
6
6
  end
data/lib/tablesalt.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
+ require "active_support/core_ext/class/attribute"
4
5
  require "short_circu_it"
5
6
 
6
7
  require "tablesalt/version"
7
8
 
9
+ require "tablesalt/dsl/defaults"
8
10
  require "tablesalt/stringable_object"
9
11
 
10
12
  module Tablesalt; 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.10.1
4
+ version: 0.10.2
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-23 00:00:00.000000000 Z
11
+ date: 2019-05-28 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/defaults.rb
52
53
  - lib/tablesalt/stringable_object.rb
53
54
  - lib/tablesalt/version.rb
54
55
  homepage: https://github.com/Freshly/spicerack/tree/master/tablesalt