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

#initialize(name, content) ⇒ Feature

Returns a new instance of Feature.



8
9
10
11
# File 'lib/bumps/feature.rb', line 8

def initialize name, content
  @name = name
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.pullObject



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

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



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

def absolute_path_under directory
  expanded_directory = File.expand_path directory
  file_path = File.expand_path(File.join(directory, file_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)


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

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



32
33
34
35
# File 'lib/bumps/feature.rb', line 32

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



28
29
30
# File 'lib/bumps/feature.rb', line 28

def write_to directory
  write_content_to absolute_path_under(directory)
end