Class: Marti::MarticleBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/marti/services/marticle_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MarticleBuilder

Returns a new instance of MarticleBuilder.



5
6
7
# File 'lib/marti/services/marticle_builder.rb', line 5

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/marti/services/marticle_builder.rb', line 3

def path
  @path
end

Instance Method Details

#buildObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/marti/services/marticle_builder.rb', line 9

def build
  Marti.cache_store.fetch("marticle/"+path, 
                                     expires_in: Marti.expires_in) do
    file = file_location(path)
    unless File.exists?(file)
      raise ::Marti::Errors::ArticleNotFoundError.new("#{path} not found") 
    end
    article = Marti::MarticleParser.new(file).parse
    article.send(:instance_variable_set, "@path".to_sym, path)
    article
  end
end