diff --git a/lib/cmock.rb b/lib/cmock.rb index e7c6aed..5b1e81e 100644 --- a/lib/cmock.rb +++ b/lib/cmock.rb @@ -1,4 +1,42 @@ $here = File.dirname __FILE__ -require "#{$here}/cmock_setup" -require "#{$here}/cmock_generator" require "#{$here}/cmock_header_parser" +require "#{$here}/cmock_generator" +require "#{$here}/cmock_file_writer" +require "#{$here}/cmock_config" +require "#{$here}/cmock_plugin_manager" +require "#{$here}/cmock_generator_utils" + +class CMock + + def initialize(mocks_path='mocks', includes=[], use_cexception=true, allow_ignore_mock=false) + @mocks_path = mocks_path + @includes = includes + @use_cexception = use_cexception + @allow_ignore_mock = allow_ignore_mock + end + + def setup_mocks(files) + files.each do |src| + generate_mock src + end + end + + private ############################### + + def generate_mock(src) + name = File.basename(src, '.h') + path = File.dirname(src) + + cm_config = CMockConfig.new(path, @mocks_path, @includes, @use_cexception, @allow_ignore_mock) + cm_parser = CMockHeaderParser.new(File.read(src)) + cm_writer = CMockFileWriter.new(cm_config) + cm_gen_utils = CMockGeneratorUtils.new(cm_config) + cm_gen_plugins = CMockPluginManager.new(cm_config, cm_gen_utils).get_generator_plugins + cm_generator = CMockGenerator.new(cm_config, name, cm_writer, cm_gen_utils, cm_gen_plugins) + + puts "Creating mock for #{name}..." + + parsed_stuff = cm_parser.parse + cm_generator.create_mock(parsed_stuff) + end +end \ No newline at end of file diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 74967c2..7a48a30 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -1,24 +1,15 @@ $here = File.dirname __FILE__ -require "#{$here}/cmock_generator_utils.rb" -require "#{$here}/cmock_generator_plugin_ignore.rb" -require "#{$here}/cmock_generator_plugin_cexception.rb" - class CMockGenerator - attr_accessor :module_name - - def initialize(config, module_name, file_writer) + def initialize(config, module_name, file_writer, utils, plugins=[]) @config = config @file_writer = file_writer @tab = @config.tab @module_name = module_name @mock_name = "Mock" + @module_name - - @utils = CMockGeneratorUtils.new( @config ) - @plugins = [] - @plugins << CMockGeneratorPluginCException.new( @config, @utils ) if @config.use_cexception - @plugins << CMockGeneratorPluginIgnore.new( @config, @utils ) if @config.allow_ignore_mock + @utils = utils + @plugins = plugins end def create_mock(parsed_stuff) diff --git a/lib/cmock_plugin_manager.rb b/lib/cmock_plugin_manager.rb new file mode 100644 index 0000000..ce92aaa --- /dev/null +++ b/lib/cmock_plugin_manager.rb @@ -0,0 +1,20 @@ + +require "#{$here}/cmock_generator_plugin_ignore.rb" +require "#{$here}/cmock_generator_plugin_cexception.rb" + +class CMockPluginManager + + def initialize(config, utils) + @config = config + @utils = utils + end + + def get_generator_plugins + @plugins = [] + @plugins << CMockGeneratorPluginCException.new( @config, @utils ) if @config.use_cexception + @plugins << CMockGeneratorPluginIgnore.new( @config, @utils ) if @config.allow_ignore_mock + return @plugins + end +end + +#!!!!!!!!!!!!!!!!!!!!!!!!! eventually I plan to scan a plugin directory to pull in all this stuff, and maybe check the yaml file after that to see what is currently allowed. that sounds swank, no? diff --git a/lib/cmock_setup.rb b/lib/cmock_setup.rb deleted file mode 100644 index 7d88c8d..0000000 --- a/lib/cmock_setup.rb +++ /dev/null @@ -1,40 +0,0 @@ -$here = File.dirname __FILE__ -require "#{$here}/cmock_header_parser" -require "#{$here}/cmock_generator" -require "#{$here}/cmock_file_writer" -require "#{$here}/cmock_config" - -class CMockSetup - - attr_accessor :mocks_path, :auto_path - - def initialize(mocks_path='mocks', includes=[], use_cexception=true, allow_ignore_mock=false) - @mocks_path = mocks_path - @includes = includes - @use_cexception = use_cexception - @allow_ignore_mock = allow_ignore_mock - end - - def setup_mocks(files) - files.each do |src| - generate_mock src - end - end - - private - - def generate_mock(src) - name = File.basename(src, '.h') - path = File.dirname(src) - - cmc = CMockConfig.new(path, @mocks_path, @includes, @use_cexception, @allow_ignore_mock) - cmp = CMockHeaderParser.new(File.read(src)) - cmf = CMockFileWriter.new(cmc) - cmg = CMockGenerator.new(cmc, name, cmf) - - puts "Creating mock for #{name}..." - - parsed_stuff = cmp.parse - cmg.create_mock(parsed_stuff) - end -end