erb_asterisk 0.0.14 → 0.0.15

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
  SHA1:
3
- metadata.gz: bcf4a610f1430f15b08437cc1e1bb8b09f31bcbc
4
- data.tar.gz: f1f6ee972dfb99dd839b51bc1016e692ab1c3eb3
3
+ metadata.gz: 6f0fecca0c2117fa73b3d92f12f140d8671025c9
4
+ data.tar.gz: 327785c07af5c5a5e6e04c74d9c6d8729083a1b5
5
5
  SHA512:
6
- metadata.gz: b5fe4467d64751959d1951d01a62cc897e61b81f0f51bc1fda1cf379299e07b39ab89bc594a31cf17712046cfdedbce49caa42b665c05429cc7ca5fbb349b3a8
7
- data.tar.gz: e75e9c4e19cd4ac6e792b4d5ade0ee0f337e235c6aadc0bb25225fda637cb9bd6b83d35ef761fd4ae8a42ad9a92af843dc15c45f9224458439d47b8cd1872918
6
+ metadata.gz: 136c2ebd6398372f08ad093f4e5d085cc0c3298468457eae8721ecdaff481ee35126e5cb39ff43503c703be3fcb53be45b37712af73f228da11a2b00b69567f8
7
+ data.tar.gz: 373e733cee4fde8433bece09e7363c32840fe86ce43e8a21b69f2e1327eea338f40d8a6bd2b876ad96e96f2229569612bc7b3adea624bde516acf759751da4fe
@@ -3,22 +3,20 @@ module ErbAsterisk
3
3
  # Declare current config file inclusion to file_name
4
4
  # args can has :priority key (larger the number - higher the priority)
5
5
  def include_to(file_name, args = {})
6
- return unless TOPLEVEL_BINDING.local_variable_defined?(:current_conf_file)
7
6
  default_args!(args)
8
7
  @exports[file_name] = [] if @exports[file_name].nil?
9
8
 
10
9
  arr = @exports[file_name]
11
10
 
12
- current_conf_file = TOPLEVEL_BINDING.local_variable_get(:current_conf_file)
13
- unless arr.index { |i| i[:file] == current_conf_file }.nil?
11
+ unless arr.index { |i| i[:file] == @current_conf_file }.nil?
14
12
  log_warn(
15
- "Skip #{current_conf_file} duplicate inclusion to #{file_name}")
13
+ "Skip #{@current_conf_file} duplicate inclusion to #{file_name}")
16
14
  return
17
15
  end
18
16
 
19
- log_debug("include_to: #{current_conf_file}, #{file_name}, #{args}", 2)
17
+ log_debug("include_to: #{@current_conf_file}, #{file_name}, #{args}", 2)
20
18
 
21
- arr << { file: current_conf_file, priority: args[:priority] }
19
+ arr << { file: @current_conf_file, priority: args[:priority] }
22
20
  "; Included to \"#{file_name}\""
23
21
  end
24
22
  end
@@ -0,0 +1,17 @@
1
+ require 'digest'
2
+
3
+ module ErbAsterisk
4
+ module SoftWrite
5
+ # Write to file only if something has changed
6
+ def soft_write(file_name, content)
7
+ if !File.exist?(file_name) ||
8
+ Digest::MD5.hexdigest(File.read(file_name)) !=
9
+ Digest::MD5.hexdigest(content)
10
+ File.write(file_name, content)
11
+ return true
12
+ end
13
+
14
+ false
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ErbAsterisk
2
- VERSION = '0.0.14'.freeze
2
+ VERSION = '0.0.15'.freeze
3
3
  end
data/lib/erb_asterisk.rb CHANGED
@@ -8,6 +8,7 @@ require 'erb_asterisk/yields'
8
8
  require 'erb_asterisk/utils'
9
9
  require 'erb_asterisk/log'
10
10
  require 'erb_asterisk/file_cache'
11
+ require 'erb_asterisk/soft_write'
11
12
 
12
13
  module ErbAsterisk
13
14
  include Render
@@ -16,6 +17,7 @@ module ErbAsterisk
16
17
  include Utils
17
18
  include Log
18
19
  include FileCache
20
+ include SoftWrite
19
21
 
20
22
  def execute(opts)
21
23
  init_instance(opts)
@@ -70,7 +72,7 @@ module ErbAsterisk
70
72
  render_erbs(erbs)
71
73
  log_debug('')
72
74
 
73
- save_erbs(erbs)
75
+ save_configs(erbs)
74
76
  export_includes(root)
75
77
  end
76
78
 
@@ -94,8 +96,8 @@ module ErbAsterisk
94
96
  # Skip on second round all erbs without yield_here method
95
97
  next if value[:skip]
96
98
 
97
- # Declare global variable with current erb file name for include_to method:
98
- TOPLEVEL_BINDING.local_variable_set(:current_conf_file, value[:config])
99
+ # Declare variable with current erb file name for include_to method:
100
+ @current_conf_file = value[:config]
99
101
  log_debug("ERB: #{file}", 1)
100
102
 
101
103
  @yield_here_occured = false
@@ -104,8 +106,12 @@ module ErbAsterisk
104
106
  end
105
107
  end
106
108
 
107
- def save_erbs(erbs)
108
- erbs.each { |_, value| File.write(value[:config], value[:content]) }
109
+ def save_configs(erbs)
110
+ erbs.each do |_, value|
111
+ config = value[:config]
112
+ next unless soft_write(config, value[:content])
113
+ log_debug("save_configs: #{config}")
114
+ end
109
115
  end
110
116
 
111
117
  def export_includes(root)
@@ -116,8 +122,9 @@ module ErbAsterisk
116
122
  s << "#include \"#{i[:file].sub(root, '')}\"\n"
117
123
  end
118
124
 
119
- File.write("#{root}#{include_file}", result)
120
- log_debug("export_includes: #{include_file}")
125
+ f = "#{root}#{include_file}"
126
+ next unless soft_write(f, result)
127
+ log_debug("export_includes: #{f}")
121
128
  end
122
129
  end
123
130
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_asterisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Baikuzin
@@ -117,6 +117,7 @@ files:
117
117
  - lib/erb_asterisk/inclusion.rb
118
118
  - lib/erb_asterisk/log.rb
119
119
  - lib/erb_asterisk/render.rb
120
+ - lib/erb_asterisk/soft_write.rb
120
121
  - lib/erb_asterisk/utils.rb
121
122
  - lib/erb_asterisk/version.rb
122
123
  - lib/erb_asterisk/yields.rb