Module: Brief::Model::AccessorMethods

Defined in:
lib/brief/model.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/brief/model.rb', line 72

def method_missing(meth, *args, &block)
  if args.empty?
    if document.respond_to?(meth)
      document.send(meth, *args, &block)
    else
      document.data && document.data.key?(meth) ? data[meth] : extracted.send(meth)
    end
  else
    super
  end
end

Instance Method Details

#contentObject



64
65
66
# File 'lib/brief/model.rb', line 64

def content
  document.content
end

#dataObject



60
61
62
# File 'lib/brief/model.rb', line 60

def data
  document.data || {}.to_mash
end

#document_titleObject



52
53
54
55
56
57
58
# File 'lib/brief/model.rb', line 52

def document_title
  data.try(:[], :title) ||
  extracted_content_data.try(:title) ||
  path.basename.to_s
    .gsub(/\.html.md/,'')
    .gsub(/\.md/,'')
end

#exists?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/brief/model.rb', line 90

def exists?
  document && document.path && document.path.exist?
end

#extractedObject



68
69
70
# File 'lib/brief/model.rb', line 68

def extracted
  @extracted ||= Brief::Document::ContentExtractor.new(self.class.type_alias, document)
end

#set_data_attribute(attribute, value) ⇒ Object



84
85
86
87
88
# File 'lib/brief/model.rb', line 84

def set_data_attribute(attribute, value)
  document.data.send("#{attribute}=", value)
  document.save
  value
end

#titleObject



48
49
50
# File 'lib/brief/model.rb', line 48

def title
  document_title
end