Class: BubbleWrap::Requirement

Inherits:
Object
  • Object
show all
Extended by:
PathManipulation
Includes:
PathManipulation
Defined in:
lib/bubble-wrap/requirement.rb,
lib/bubble-wrap/requirement/path_manipulation.rb

Defined Under Namespace

Modules: PathManipulation

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PathManipulation

convert_caller_to_path, convert_caller_to_root_path, convert_to_absolute_path, convert_to_relative, strip_up_to_last_lib

Constructor Details

#initialize(file, root) ⇒ Requirement

Returns a new instance of Requirement



11
12
13
14
# File 'lib/bubble-wrap/requirement.rb', line 11

def initialize(file,root)
  self.file = file
  self.root = root
end

Class Attribute Details

.pathsObject

Returns the value of attribute paths



52
53
54
# File 'lib/bubble-wrap/requirement.rb', line 52

def paths
  @paths
end

Instance Attribute Details

#fileObject

Returns the value of attribute file



8
9
10
# File 'lib/bubble-wrap/requirement.rb', line 8

def file
  @file
end

#file_dependenciesObject



42
43
44
# File 'lib/bubble-wrap/requirement.rb', line 42

def file_dependencies
  @file_dependencies ||= []
end

#rootObject

Returns the value of attribute root



8
9
10
# File 'lib/bubble-wrap/requirement.rb', line 8

def root
  @root
end

Class Method Details

.clear!Object



75
76
77
# File 'lib/bubble-wrap/requirement.rb', line 75

def clear!
  paths.select! { |k,v| v.relative == 'motion/shortcut.rb' }
end

.file(relative) ⇒ Object



65
66
67
# File 'lib/bubble-wrap/requirement.rb', line 65

def file(relative)
  paths.fetch(relative)
end

.files(app_files = nil) ⇒ Object



69
70
71
72
73
# File 'lib/bubble-wrap/requirement.rb', line 69

def files(app_files=nil)
  files = paths.values.map(&:to_s)
  files += app_files if app_files
  files.uniq
end

.files_dependenciesObject



79
80
81
82
83
84
85
# File 'lib/bubble-wrap/requirement.rb', line 79

def files_dependencies
  deps = {}
  paths.each_value do |file|
    deps.merge! file.dependencies
  end
  deps
end

.frameworks(app_frameworks = nil) ⇒ Object



87
88
89
90
91
92
# File 'lib/bubble-wrap/requirement.rb', line 87

def frameworks(app_frameworks=nil)
  frameworks = ['Foundation', 'CoreGraphics'] +
    paths.values.map(&:frameworks)
  frameworks += app_frameworks if app_frameworks
  frameworks.flatten.compact.sort.uniq
end

.scan(caller_location, file_spec, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/bubble-wrap/requirement.rb', line 54

def scan(caller_location, file_spec, &block)
  root = convert_caller_to_root_path caller_location
  self.paths ||= {}
  Dir.glob(File.expand_path(file_spec, root)).each do |file|
    p = new(file,root)
    self.paths[p.relative] = p
    p.depends_on('motion/shortcut.rb') unless p.relative == 'motion/shortcut.rb'
  end
  self.class_eval(&block) if block
end

Instance Method Details

#dependenciesObject



33
34
35
36
# File 'lib/bubble-wrap/requirement.rb', line 33

def dependencies
  return {} if file_dependencies.empty?
  { file => file_dependencies.map(&:to_s) }
end

#depends_on(file_or_paths) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bubble-wrap/requirement.rb', line 20

def depends_on(file_or_paths)
  paths = file_or_paths.respond_to?(:each) ? file_or_paths : [ file_or_paths ]
  self.file_dependencies += paths.map do |f|
    f = self.class.file(f) unless f.is_a? Requirement
    f unless f.file == file
  end.compact
  self.file_dependencies.uniq!(&:to_s)
end

#frameworksObject



46
47
48
# File 'lib/bubble-wrap/requirement.rb', line 46

def frameworks
  @frameworks ||= []
end

#relativeObject



16
17
18
# File 'lib/bubble-wrap/requirement.rb', line 16

def relative
  convert_to_relative(file, root)
end

#to_sObject



38
39
40
# File 'lib/bubble-wrap/requirement.rb', line 38

def to_s
  file
end

#uses_framework(framework_name) ⇒ Object



29
30
31
# File 'lib/bubble-wrap/requirement.rb', line 29

def uses_framework(framework_name)
  self.frameworks << framework_name
end