k_builder 0.0.16 → 0.0.19

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: 050b7375cf0a60393e140589a7a3517097097ca969153fc969bc47f7d4815d93
4
- data.tar.gz: 76deda3ada30401133f1ac8fc5cea88a51bd1b0b2618b53a82613cd4f85569c3
3
+ metadata.gz: f81ce6d464232f632884a2d3c1e04c180551644bf5ce9202a4a5d4a2e20d5c40
4
+ data.tar.gz: bdc67f51753f3b63944b88ad3f739ba4710bf0981190fd9d7b8ce69eea6493aa
5
5
  SHA512:
6
- metadata.gz: 7d5c01ea1307ff86b577b69f2cd4fe5307c97c75c70d873ddfa01a1ccf6205e993bcfabd3fc0c99495c5e59f2c63e031de47c6e2f720390344f36766fbe21504
7
- data.tar.gz: 5027f3bfbc0212a3cde6aa1389d2cb68f389c5381303f5dedeb2ae2fdbb0d88e372dfc7ed83875a587523f883b1e3b4c34e425db4f10fdeab9468eb63addfc4a
6
+ metadata.gz: db0ac5f45c53b1a4d7d58e9acfd5bd106402039f1d28d81c998d3279f4b1177980817b284362cd272853735f02eb492a8d131cbcade21dacf707132269b84c75
7
+ data.tar.gz: 24ff7bfeefa7db10f9a028cbda7695f171a5d7d6095be2a23637a9d3e7e727323512962414d5236d6961d4864aa4aad3521770f33120f2df07740671878a9e70
data/k_builder.gemspec CHANGED
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
39
39
  # spec.extensions = ['ext/k_builder/extconf.rb']
40
40
 
41
41
  spec.add_dependency 'handlebars-helpers', '~> 0'
42
- # spec.add_dependency 'tty-box', '~> 0.5.0'
42
+ # spec.add_dependency "anyway_config" , ">= 2.0.0"
43
+ # spec.add_dependency "config" , ">= 3.0.0"
43
44
  end
data/lib/k_builder.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'k_builder/version'
4
+ require 'k_builder/base_configuration'
4
5
  require 'k_builder/configuration'
5
6
  require 'k_builder/base_builder'
6
7
  require 'k_builder/builder'
@@ -70,35 +70,42 @@ module KBuilder
70
70
  hash
71
71
  end
72
72
 
73
- # builds a nested structure by either builder block or hash
74
- # @param data_structure [type=DataStructure]
75
- # @param builder [type=Builder]
76
- # @param attributes [type=Hash|DataStructure instance]
77
- # @param &block
78
- #
79
- # @return [type=Hash]
80
- def build_nested(data_structure, builder, attributes = {}, &block)
81
- if block_given?
82
- builder.build(&block).to_h
83
- else
84
- build_hash(data_structure, attributes)
85
- end
86
- end
73
+ # TODO
74
+ # Support Nesting
75
+ # Support Generation fo the following
76
+ # - fluent set_
77
+ # - Support setter (non-fluent)
78
+ # - Support getter (non-fluent)
79
+
80
+ # # builds a nested structure by either builder block or hash
81
+ # # @param data_structure [type=DataStructure]
82
+ # # @param builder [type=Builder]
83
+ # # @param attributes [type=Hash|DataStructure instance]
84
+ # # @param &block
85
+ # #
86
+ # # @return [type=Hash]
87
+ # def build_nested(data_structure, builder, attributes = {}, &block)
88
+ # if block_given?
89
+ # builder.build(&block).to_h
90
+ # else
91
+ # build_hash(data_structure, attributes)
92
+ # end
93
+ # end
87
94
 
88
95
  private
89
96
 
90
- #
91
- # @param data_structure [type=DataStructure]
92
- # @param attributes [type=Hash, DataStructure]
93
- #
94
- # @return [type=Hash]
95
- def build_hash(data_structure, attributes)
96
- if attributes.is_a?(data_structure)
97
- attributes.to_h
98
- else
99
- data_structure.new(attributes).to_h
100
- end
101
- end
97
+ # #
98
+ # # @param data_structure [type=DataStructure]
99
+ # # @param attributes [type=Hash, DataStructure]
100
+ # #
101
+ # # @return [type=Hash]
102
+ # def build_hash(data_structure, attributes)
103
+ # if attributes.is_a?(data_structure)
104
+ # attributes.to_h
105
+ # else
106
+ # data_structure.new(attributes).to_h
107
+ # end
108
+ # end
102
109
 
103
110
  # Defines all of the necessary builder setter methods
104
111
  #
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ # Base configuration object for all k_builder* GEM
5
+ class BaseConfiguration
6
+ def to_hash
7
+ hash = {}
8
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
9
+ hash
10
+ end
11
+
12
+ def kv(name, value)
13
+ puts "#{name.rjust(30)} : #{value}"
14
+ end
15
+
16
+ # All of this code should be extracted into a module
17
+ #
18
+ # The module should then be extracted out into a GEM so that
19
+ # I can include it as needed. The GEM might be called
20
+ # (dynamic attributes) and would allow a regular class to act like an OpenStruct
21
+ # K-DSL uses data hash, while base configuration uses instance variables
22
+
23
+ def respond_to_missing?(name, *_args, &_block)
24
+ # puts 'respond_to_missing?'
25
+ # puts "respond_to_missing: #{name}"
26
+ n = name.to_s
27
+ n = n[0..-2] if n.end_with?('=')
28
+
29
+ if n.end_with?('?')
30
+ super
31
+ else
32
+ # This has not been fully tested
33
+ instance_variable_defined?("@#{n}") || super
34
+ end
35
+ end
36
+
37
+ def method_missing(name, *args, &_block)
38
+ # puts "method_missing: #{name}"
39
+ # puts "args.length : #{args.length}"
40
+
41
+ add_getter_or_param_method(name)
42
+ add_setter_method(name)
43
+
44
+ send(name, args[0]) if args.length == 1 # name.end_with?('=')
45
+
46
+ super unless self.class.method_defined?(name)
47
+ end
48
+
49
+ # Handles Getter method and method with single parameter
50
+ # object.my_name
51
+ # object.my_name('david')
52
+ def add_getter_or_param_method(name)
53
+ # L.progress(1, 'add_getter_or_param_method')
54
+ self.class.class_eval do
55
+ # L.progress(2, 'add_getter_or_param_method')
56
+ name = name.to_s.gsub(/=$/, '')
57
+ # L.progress(3, 'add_getter_or_param_method')
58
+ # L.kv 'name', name
59
+ define_method(name) do |*args|
60
+ # L.progress(4, 'add_getter_or_param_method')
61
+ # L.kv 'add_getter_or_param_method', name
62
+ raise KBuilder::Error, 'Multiple setting values is not supported' if args.length > 1
63
+
64
+ if args.length.zero?
65
+ get_value(name)
66
+ else
67
+ send("#{name}=", args[0])
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ # Handles Setter method
74
+ # object.my_name = 'david'
75
+ def add_setter_method(name)
76
+ # L.progress(1, 'add_setter_method')
77
+ self.class.class_eval do
78
+ # L.progress(2, 'add_setter_method')
79
+ name = name.to_s.gsub(/=$/, '')
80
+ # L.progress(3, 'add_setter_method')
81
+ # L.kv 'add_setter_method', name
82
+ define_method("#{name}=") do |value|
83
+ # L.progress(4, 'add_setter_method')
84
+ # L.kv 'name', name
85
+ # L.kv 'value', value
86
+ instance_variable_set("@#{name}", value)
87
+ # my_data[name.to_s] = value
88
+ end
89
+ end
90
+ end
91
+
92
+ def get_value(name)
93
+ instance_variable_get("@#{name}")
94
+ end
95
+ end
96
+
97
+ # class L
98
+ # def self.progress(index, label)
99
+ # puts "#{index} - #{label}"
100
+ # end
101
+
102
+ # def self.kv(name, value)
103
+ # puts "#{name.rjust(30)} : #{value}"
104
+ # end
105
+ # end
106
+ end
@@ -105,11 +105,13 @@ module KBuilder
105
105
  end
106
106
 
107
107
  # Setter for template folder
108
+ # Refactor: Make Private
108
109
  def template_folder=(value)
109
110
  hash['template_folder'] = File.expand_path(value)
110
111
  end
111
112
 
112
113
  # Getter for template folder
114
+ # Refactor: generate
113
115
  def template_folder
114
116
  hash['template_folder']
115
117
  end
@@ -125,11 +127,13 @@ module KBuilder
125
127
  end
126
128
 
127
129
  # Setter for global template folder
130
+ # Refactor: Make Private
128
131
  def global_template_folder=(value)
129
132
  hash['global_template_folder'] = File.expand_path(value)
130
133
  end
131
134
 
132
135
  # Setter for global template folder
136
+ # Refactor: generate
133
137
  def global_template_folder
134
138
  hash['global_template_folder']
135
139
  end
@@ -20,12 +20,13 @@ module KBuilder
20
20
  end
21
21
 
22
22
  # Configuration class
23
- class Configuration
23
+ class Configuration < BaseConfiguration
24
24
  attr_accessor :target_folder
25
25
  attr_accessor :template_folder
26
26
  attr_accessor :global_template_folder
27
27
 
28
28
  def initialize
29
+ super
29
30
  @target_folder = Dir.getwd
30
31
  @template_folder = File.join(Dir.getwd, '.templates')
31
32
  @global_template_folder = nil
@@ -38,17 +39,5 @@ module KBuilder
38
39
  kv 'template_folder' , template_folder
39
40
  kv 'global_template_folder', global_template_folder
40
41
  end
41
-
42
- def to_hash
43
- hash = {}
44
- instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
45
- hash
46
- end
47
-
48
- private
49
-
50
- def kv(name, value)
51
- puts "#{name.rjust(30)} : #{value}"
52
- end
53
42
  end
54
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.16'
4
+ VERSION = '0.0.19'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -54,6 +54,7 @@ files:
54
54
  - k_builder.gemspec
55
55
  - lib/k_builder.rb
56
56
  - lib/k_builder/base_builder.rb
57
+ - lib/k_builder/base_configuration.rb
57
58
  - lib/k_builder/builder.rb
58
59
  - lib/k_builder/configuration.rb
59
60
  - lib/k_builder/version.rb