Class: Cup::Cupfile

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

Defined Under Namespace

Classes: CupfileError, DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Cupfile

Returns a new instance of Cupfile.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cup/cupfile.rb', line 8

def initialize path

  @path = path
  @javascript_patterns = {}
  @uglifier_options = {}
  @before_build = lambda {}
  @after_build = lambda {}
  @validation_errors = []

  %w{vendor spec lib src}.each do |dir|
    set_javascript_patterns_for dir.to_sym, :*
  end

  cup_define_block = eval(File.read(path), binding, path.to_s)
  DSL.interpret self, &cup_define_block
end

Instance Attribute Details

#after_buildObject (readonly)

Returns the value of attribute after_build.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def after_build
  @after_build
end

#before_buildObject (readonly)

Returns the value of attribute before_build.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def before_build
  @before_build
end

#licenceObject (readonly)

Returns the value of attribute licence.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def licence
  @licence
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def name
  @name
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/cup/cupfile.rb', line 5

def path
  @path
end

#uglifier_optionsObject (readonly)

Returns the value of attribute uglifier_options.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def uglifier_options
  @uglifier_options
end

#validation_errorsObject (readonly)

Returns the value of attribute validation_errors.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def validation_errors
  @validation_errors
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/cup/cupfile.rb', line 6

def version
  @version
end

Instance Method Details

#error_messages(join = ', ') ⇒ Object



64
65
66
# File 'lib/cup/cupfile.rb', line 64

def error_messages(join=', ')
  @validation_errors.join join
end

#javascriptsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cup/cupfile.rb', line 25

def javascripts

  javascripts = {}
  current_directory = File.dirname(File.expand_path(self.path))
  
  @javascript_patterns.each do |subdir, patterns|
    javascripts[subdir] = patterns.map do |pattern|

      default_catch_all = pattern == :*

      pattern = '**/*.js' if default_catch_all

      if pattern
        expanded_pattern = current_directory + "/#{subdir}/#{pattern}"
        FileList[expanded_pattern].select do |f|
          if subdir == :spec and f.start_with?(current_directory + "/spec/visual")
            false
          else
            File.extname(f).downcase == '.js'
          end
        end
      end
    end.flatten.compact.uniq
  end

  javascripts
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
# File 'lib/cup/cupfile.rb', line 53

def valid?
  @validation_errors = []

  validation_error 'cupfile error, path not specified' if path.nil?
  validation_error 'name is required' if name.nil? or name.strip.size == 0
  validation_error 'version is require and must be of the form X.Y.Z where X, Y and Z are numbers' unless version =~ /\d+\.\d+\.\d+/
  validation_error "licence file '#{licence}' does not exist" unless licence_file_exists?

  @validation_errors.empty?
end