Class: Meanbee::Modbuild::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/modbuild.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_directory) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/modbuild.rb', line 13

def initialize(module_directory)
  @logger = Logger.new(STDERR)
  @logger.level = Logger::FATAL
  
  @module_location = module_directory
  @modman_location = File.join(module_directory, 'modman')
  @magento_location = File.join(module_directory, '..', '..')
  
  @package_name = 'Unspecified_Name'
  @package_version = '1.0.0'
  @package_summary = 'Unspecified package summary'
  @package_description = 'Unspecified package description'
  @package_files = []
end

Instance Attribute Details

#package_descriptionObject

Returns the value of attribute package_description.



11
12
13
# File 'lib/modbuild.rb', line 11

def package_description
  @package_description
end

#package_nameObject

Returns the value of attribute package_name.



11
12
13
# File 'lib/modbuild.rb', line 11

def package_name
  @package_name
end

#package_summaryObject

Returns the value of attribute package_summary.



11
12
13
# File 'lib/modbuild.rb', line 11

def package_summary
  @package_summary
end

#package_versionObject

Returns the value of attribute package_version.



11
12
13
# File 'lib/modbuild.rb', line 11

def package_version
  @package_version
end

Instance Method Details

#buildObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/modbuild.rb', line 32

def build
  @logger.debug "Module Directory: #{@module_location}"
  @logger.debug "Modman Directory: #{@modman_location}"
  @logger.debug "Magento Directory: #{@magento_location}"
  
  get_package_files
  
  @logger.debug 'Generating XML file..'
  package_xml = PackageXml.new @package_name, @package_version, @package_summary, @package_description
  
  @package_files.each do |file|
    package_xml.add_file file
  end
  
  return package_xml.to_string
end

#enable_debugObject



28
29
30
# File 'lib/modbuild.rb', line 28

def enable_debug
  @logger.level = Logger::DEBUG
end

#get_package_filesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/modbuild.rb', line 49

def get_package_files
  # List all of the files related to this module, base on the modman contents
  modman_file = File.new @modman_location, 'r'

  @logger.debug "Reading modman file"
  while (line = modman_file.gets)
    line.chomp!
    
    if (line =~ /^\s*#/)
      @logger.debug "  Comment line: #{line}"
      if (/^#\s*(?<key>\w+)\s*:\s*(?<value>.*)$/ =~ line)
        @logger.debug "    Extracted: #{key} = #{value}"
        
        case key.downcase.to_sym
          when :name
            @package_name = value
          when :version
            @package_version = value
          when :summary
            @package_summary = value
          when :description
            @package_description = value
          else
            @logger.debug "      Unknown package variables"
        end
      end
    elsif (line =~ /^.*\s+.*$/)
      @logger.debug "  Line: #{line}"
      # local_file is the file in the .modman directory, the magento_file is where
      # the file is placed in the magento root
      local_file, magento_file = line.split ' '

      @logger.debug "    Local: #{local_file}"
      @logger.debug "    Magento: #{magento_file}"

      if local_file.match /\*$/
        local_file_directory = File.dirname local_file

        @logger.debug "      Identified as glob"
        @logger.debug "      Local file directory: #{local_file_directory}"

        Dir.glob(File.join(@module_location, local_file)).each do |f|
          @logger.debug "        Globbed file: #{f}"

          f_regex = Regexp.new "^#{@module_location}\/?"
          f_relative = f.gsub(f_regex, '')

          @logger.debug "        Adding: #{f_relative}"
          @package_files << f_relative
        end
      else
        @logger.debug "    Adding: #{magento_file}"
        @package_files << magento_file
      end
    end
  end
  
  modman_file.close
  
  return @package_files
end