k_doc 0.0.26 → 0.0.27

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: e43e7408a95cf8bf701922e28ef33115d12dd66dd77af00ca1f8b0e492c0952d
4
- data.tar.gz: 74506c87934ece30b1e5e37b111fc6ff347ae277b8085aff50a0dce698946b7c
3
+ metadata.gz: 13425498035dd9742336c907655e6555a37f7b4293c99443921bea29b38b0db9
4
+ data.tar.gz: 63ff3b0ad02f17833cc23318d529c80cc1e0165eae4d18fb096db484f331808b
5
5
  SHA512:
6
- metadata.gz: 92427570dd666fa9d679472fe48dd79771a877209ddd80df4143db1b03cf75ed587af99b1bca3f39e4f039e6ffa4e074c2173f19f8047811a17ca6c7d25cf248
7
- data.tar.gz: 553d2c7d0bbf1304b7814e3196b3bf4d90a413c920c2209865918dd3351edabcd6fdad345cb4deb53fb5cb2678b637992caf00a7349218030a37518605071206
6
+ metadata.gz: d623d3964433ecbd4b33d4c4cce608d5e1923836ab6ffb3ab91c05dc9ae517719d2da2a14ca0ab3c83e5cace4593d2afaad80f24eaa4c8e8e48dd7b6229c886a
7
+ data.tar.gz: 9557e8c8082bcfed3acb10fea6a4516e7aec04a49cfdf3f99fb3800faf32531937df8f52278db7a0e02f6543b8e22e25bbadef7d472e530a5ccaf6c8ae053081
data/.rubocop.yml CHANGED
@@ -56,8 +56,7 @@ Style/EmptyMethod:
56
56
  Exclude:
57
57
  - "**/spec/**/*"
58
58
  Style/OpenStructUse:
59
- Exclude:
60
- - "**/spec/**/*"
59
+ Enabled: false
61
60
  Metrics/ClassLength:
62
61
  Enabled: false
63
62
  Metrics/ModuleLength:
@@ -25,7 +25,7 @@ module KDoc
25
25
 
26
26
  initialize_tag(opts)
27
27
  initialize_data(opts)
28
- initialize_import(opts) if respond_to?(:initialize_import)
28
+ initialize_import(opts)
29
29
  initialize_block(opts, &block)
30
30
  end
31
31
 
@@ -37,6 +37,10 @@ module KDoc
37
37
  @default_data_type ||= Hash
38
38
  end
39
39
 
40
+ def os(**opts)
41
+ OpenStruct.new(opts)
42
+ end
43
+
40
44
  def debug
41
45
  debug_taggable
42
46
  debug_block_processor
@@ -21,7 +21,8 @@ module KDoc
21
21
  @block_state == :actioned
22
22
  end
23
23
 
24
- def execute_block(run_actions: nil)
24
+ def execute_block(run_importer: nil, run_actions: nil)
25
+ run_on_import if run_importer
25
26
  eval_block
26
27
  run_on_action if run_actions
27
28
  end
@@ -6,47 +6,22 @@ module KDoc
6
6
  module Importable
7
7
  include KLog::Logging
8
8
 
9
- attr_reader :importer
9
+ # Proc/Handler to be called when importing data
10
+ attr_reader :on_import
11
+
12
+ # OpenStruct to be populated with data from import
10
13
  attr_reader :imports
11
14
 
12
- # Imports are provided via an options hash, these imports are remove from the hash as they are read
13
- #
14
- # Any container can import data from an existing container via the import options
15
- # rubocop:disable Style/OpenStructUse
16
15
  def initialize_import(opts)
17
16
  # log.error 'initialize_import'
18
- @importer = opts.delete(:importer)
17
+ @on_import = opts.delete(:on_import)
19
18
  @imports = OpenStruct.new
20
19
  end
21
- # rubocop:enable Style/OpenStructUse
22
-
23
- def call_importer
24
- return unless importer
25
-
26
- importer.call(self)
27
- end
28
-
29
- # def import(tag)
30
- # KManager.find_document(tag)
31
- # end
32
-
33
- # def import_data(tag, as: :document)
34
- # doc = KManager.find_document(tag)
35
-
36
- # return nil unless doc&.data
37
-
38
- # # log.error 'about to import'
39
- # doc.debug(include_header: true)
40
-
41
- # return KUtil.data.to_open_struct(doc.data) if %i[open_struct ostruct].include?(as)
42
-
43
- # doc.data
44
- # end
45
20
 
46
- protected
21
+ def run_on_import
22
+ return unless on_import
47
23
 
48
- def debug_importable
49
- # log.kv 'class type' , self.class.name , debug_pad_size
24
+ instance_eval(&on_import)
50
25
  end
51
26
  end
52
27
  end
data/lib/k_doc/model.rb CHANGED
@@ -23,6 +23,12 @@ module KDoc
23
23
 
24
24
  # Need to look at Director as an alternative to this technique
25
25
  def settings(key = nil, **setting_opts, &block)
26
+ # TODO: add test
27
+ if block.nil?
28
+ log.warn 'You cannot call settings without a block. Did you mean to call data[:settings] or odata.settings?'
29
+ return
30
+ end
31
+
26
32
  setting_opts ||= {}
27
33
 
28
34
  setting_opts = {}.merge(opts) # Container options
@@ -34,6 +40,11 @@ module KDoc
34
40
  end
35
41
 
36
42
  def table(key = :table, **opts, &block)
43
+ if block.nil?
44
+ log.warn 'You cannot call table without a block. Did you mean to call data[:table] or odata.table?'
45
+ return
46
+ end
47
+
37
48
  # NEED to add support for run_decorators I think
38
49
  opts.merge(parent: self)
39
50
  table_instance(data, key, **opts, &block)
@@ -33,6 +33,10 @@ module KDoc
33
33
  end
34
34
  end
35
35
 
36
+ def imports
37
+ parent.imports
38
+ end
39
+
36
40
  # Return these settings which are attached to a data container using :key
37
41
  # internal_data is a bad name, but it is unlikely to interfere with any setting names
38
42
  # Maybe I rename this to raw_data
data/lib/k_doc/table.rb CHANGED
@@ -20,6 +20,10 @@ module KDoc
20
20
  run_decorators(:update_rows)
21
21
  end
22
22
 
23
+ def imports
24
+ parent.imports
25
+ end
26
+
23
27
  # Pass fields in using the following format
24
28
  # fields :name, f(:type, :string), :db_type
25
29
  #
data/lib/k_doc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDoc
4
- VERSION = '0.0.26'
4
+ VERSION = '0.0.27'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-13 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport