jdzak-cf_case_check 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
 
2
2
  module CaseCheck
3
3
  # :stopdoc:
4
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.2.3'.freeze
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -0,0 +1,63 @@
1
+ require 'pathname'
2
+ require "rexml/document"
3
+
4
+ module CaseCheck
5
+
6
+ class Coldfusion8Configuration
7
+ PATH, CONFIG_FILENAME = 'lib', 'neo-runtime.xml'
8
+
9
+ def initialize(cf_root)
10
+ @cf_root = cf_root
11
+ absolute_filename = File.join(@cf_root, PATH, CONFIG_FILENAME)
12
+ config = File.new(absolute_filename)
13
+ @doc = REXML::Document.new(config)
14
+ apply
15
+ end
16
+
17
+ private
18
+
19
+ def apply
20
+ read_custom_tag_dirs
21
+ read_cfc_dirs
22
+ end
23
+
24
+ def read_custom_tag_dirs
25
+ CustomTag.directories = absolutize_directories(custom_tag_directories || [])
26
+ end
27
+
28
+ def read_cfc_dirs
29
+ Cfc.directories = absolutize_directories(cfc_directories || [])
30
+ end
31
+
32
+
33
+
34
+ private
35
+ def custom_tag_directories
36
+ absolutize_directories(all_directories).reject do |d|
37
+ (Dir["#{d}/**/*.cfm"] + Dir["#{d}/**/*.tem"]).empty?
38
+ end
39
+ end
40
+
41
+ def cfc_directories
42
+ absolutize_directories(all_directories).reject do |d|
43
+ Dir["#{d}/**/*.cfc"].empty?
44
+ end
45
+ end
46
+
47
+ def all_directories
48
+ @doc.elements.collect("//var[contains(@name,'customtag')]/string") { |e| e.text }
49
+ end
50
+
51
+ def absolutize_directories(dirs)
52
+ dirs.to_a.collect { |d|
53
+ p = Pathname.new(d)
54
+ if p.absolute?
55
+ p
56
+ else
57
+ Pathname.new(File.dirname(@filename)) + p
58
+ end
59
+ }.collect { |p| p.to_s }
60
+ end
61
+ end
62
+
63
+ end
@@ -68,7 +68,7 @@ module CaseCheck
68
68
  def read_config!
69
69
  @configuration =
70
70
  if coldfusion_directory_given && File.exist?(coldfusion_directory)
71
- CaseCheck::Coldfusion8Configuration.new(coldfusion_directory)
71
+ Coldfusion8Configuration.new(coldfusion_directory)
72
72
  elsif File.exist?(configuration_file)
73
73
  Configuration.new(configuration_file)
74
74
  end
@@ -0,0 +1,65 @@
1
+ require 'fileutils'
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe CaseCheck::Coldfusion8Configuration do
5
+ before do
6
+ @cf_root = "/tmp/cf_case_check/"
7
+
8
+ neo_runtime = {
9
+ :filename => "/tmp/cf_case_check/lib/neo-runtime.xml",
10
+ :contents => <<-XML
11
+ <wddxPacket version='1.0'>
12
+ <data>
13
+ <struct type='coldfusion.server.ConfigMap'>
14
+ <var name='/WEB-INF/customtags1207698058868'><string>/tmp/cf_case_check/customtags</string></var>
15
+ <var name='/WEB-INF/customtags1207758745211'><string>/tmp/cf_case_check/cfcs</string></var>
16
+ <var name='/WEB-INF/customtags1207773084805'><string>/tmp/cf_case_check/misc</string></var>
17
+ <wrong name='no/customtags/here'><string>fail</string></wrong>
18
+ </struct>
19
+ </data>
20
+ </wddxPacket>
21
+ XML
22
+ }
23
+
24
+ create_file(neo_runtime[:filename], neo_runtime[:contents])
25
+ end
26
+
27
+ after do
28
+ if File.exist?(@cf_root)
29
+ FileUtils.rm_rf @cf_root
30
+ end
31
+ end
32
+
33
+ def create_file(filename, contents)
34
+ touch(filename)
35
+ File.open(filename, 'w') { |f| f.write contents }
36
+ end
37
+
38
+ def touch(filename)
39
+ FileUtils.mkdir_p File.dirname(filename)
40
+ File.open(filename, 'w')
41
+ end
42
+
43
+ def build_config
44
+ CaseCheck::Coldfusion8Configuration.new(@cf_root)
45
+ end
46
+
47
+ it "should read customtag directories from neo-runtime.xml" do
48
+ touch('/tmp/cf_case_check/customtags/alpha.cfm')
49
+ touch('/tmp/cf_case_check/misc/beta.cfm')
50
+
51
+ build_config
52
+
53
+ CaseCheck::CustomTag.directories.should == %w(/tmp/cf_case_check/customtags /tmp/cf_case_check/misc)
54
+ end
55
+
56
+ it "should read cfc directories from neo-runtime.xml" do
57
+ touch('/tmp/cf_case_check/cfcs/gamma.cfc')
58
+ touch('/tmp/cf_case_check/misc/delta.cfc')
59
+
60
+ build_config
61
+
62
+ CaseCheck::Cfc.directories.should == %w(/tmp/cf_case_check/cfcs /tmp/cf_case_check/misc)
63
+ end
64
+
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdzak-cf_case_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rhett Sutphin
@@ -51,6 +51,7 @@ files:
51
51
  - lib/case_check/coldfusion_source.rb
52
52
  - lib/case_check/commands.rb
53
53
  - lib/case_check/configuration.rb
54
+ - lib/case_check/coldfusion_8_configuration.rb
54
55
  - lib/case_check/core-ext.rb
55
56
  - lib/case_check/reference.rb
56
57
  - lib/case_check/references/cfc.rb
@@ -60,6 +61,7 @@ files:
60
61
  - spec/coldfusion_source_spec.rb
61
62
  - spec/commands_spec.rb
62
63
  - spec/configuration_spec.rb
64
+ - spec/coldfusion_8_configuration_spec.rb
63
65
  - spec/core_ext_spec.rb
64
66
  - spec/reference_spec.rb
65
67
  - spec/references/cfc_spec.rb