Class: Bumps::Feature
- Inherits:
-
Object
- Object
- Bumps::Feature
- Defined in:
- lib/bumps/feature.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_path_under(directory) ⇒ Object
- #eql?(match) ⇒ Boolean
-
#initialize(name, content) ⇒ Feature
constructor
A new instance of Feature.
- #write_content_to(file_path) ⇒ Object
- #write_to(directory) ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/bumps/feature.rb', line 6 def content @content end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/bumps/feature.rb', line 6 def name @name end |
Class Method Details
.pull ⇒ Object
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 = File. directory file_path = File.(File.join(directory, file_name)) unless file_path =~ /^#{}/ raise "Could not write feature to path #{file_path}, path is not below #{}" end file_path end |
#eql?(match) ⇒ 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 |