Class: Bumps::Feature

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeature

Returns a new instance of Feature.



6
7
8
9
# File 'lib/bumps/feature.rb', line 6

def initialize
  @name = ''
  @content = ''
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/bumps/feature.rb', line 4

def content
  @content
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/bumps/feature.rb', line 4

def name
  @name
end

Class Method Details

.pullObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bumps/feature.rb', line 11

def self.pull
  Configuration.output_stream << "Retrieving features from #{Configuration.pull_url} ...\n"
  begin
    features = RemoteFeature.fetch(Configuration.pull_url)
  rescue Exception => e
    Configuration.output_stream << "Could not pull features: #{e}\n"
    features = []
  end
    
  features.each do |feature|
    feature.write_to Configuration.feature_directory
  end
  Configuration.output_stream << "Wrote #{features.size} features to #{Configuration.feature_directory}\n\n"
end

Instance Method Details

#absolute_path_under(directory) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/bumps/feature.rb', line 35

def absolute_path_under directory
  expanded_directory = File.expand_path directory
  file_path = File.expand_path(File.join(directory, name))
  unless file_path =~ /^#{expanded_directory}/
     raise "Could not write feature to path #{file_path}, path is not below #{expanded_directory}"
   end
  file_path
end

#eql?(match) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/bumps/feature.rb', line 44

def eql? match
  self.instance_variables.each do |attr|
    self_attr = self.instance_variable_get(attr)
    match_attr = match.instance_variable_get(attr)
    return false unless self_attr == match_attr
  end
    
  true
end

#write_content_to(file_path) ⇒ Object



30
31
32
33
# File 'lib/bumps/feature.rb', line 30

def write_content_to file_path
  FileUtils.makedirs File.dirname(file_path)
  File.open(file_path, 'w') {|f| f.write(content) }
end

#write_to(directory) ⇒ Object



26
27
28
# File 'lib/bumps/feature.rb', line 26

def write_to directory
  write_content_to absolute_path_under(directory)
end