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
  @javascripts = {}
  @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



40
41
42
# File 'lib/cup/cupfile.rb', line 40

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

#javascriptsObject



25
26
27
# File 'lib/cup/cupfile.rb', line 25

def javascripts
  @javascripts
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
# File 'lib/cup/cupfile.rb', line 29

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