Class: Cup::Cupfile
- Inherits:
-
Object
- Object
- Cup::Cupfile
- Defined in:
- lib/cup/cupfile.rb
Defined Under Namespace
Classes: CupfileError, DSL
Instance Attribute Summary collapse
-
#after_build ⇒ Object
readonly
Returns the value of attribute after_build.
-
#before_build ⇒ Object
readonly
Returns the value of attribute before_build.
-
#licence ⇒ Object
readonly
Returns the value of attribute licence.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#validation_errors ⇒ Object
readonly
Returns the value of attribute validation_errors.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #error_messages(join = ', ') ⇒ Object
-
#initialize(path) ⇒ Cupfile
constructor
A new instance of Cupfile.
- #javascripts ⇒ Object
- #valid? ⇒ Boolean
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_build ⇒ Object (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_build ⇒ Object (readonly)
Returns the value of attribute before_build.
6 7 8 |
# File 'lib/cup/cupfile.rb', line 6 def before_build @before_build end |
#licence ⇒ Object (readonly)
Returns the value of attribute licence.
6 7 8 |
# File 'lib/cup/cupfile.rb', line 6 def licence @licence end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cup/cupfile.rb', line 6 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/cup/cupfile.rb', line 5 def path @path end |
#validation_errors ⇒ Object (readonly)
Returns the value of attribute validation_errors.
6 7 8 |
# File 'lib/cup/cupfile.rb', line 6 def validation_errors @validation_errors end |
#version ⇒ Object (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 (join=', ') @validation_errors.join join end |
#javascripts ⇒ Object
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.(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 = current_directory + "/#{subdir}/#{pattern}" FileList[].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
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 |