Class: Trundle::TextBundle

Inherits:
Object
  • Object
show all
Extended by:
InfoAccessors
Defined in:
lib/trundle/text_bundle.rb

Instance Method Summary collapse

Methods included from InfoAccessors

info_accessors

Constructor Details

#initialize(path) ⇒ TextBundle

Returns a new instance of TextBundle.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trundle/text_bundle.rb', line 13

def initialize(path)
  @path = path
  @info_store = Trundle::InfoStore.new(File.join(@path, 'info.json'))
  @text_store = Trundle::TextStore.new(File.join(@path, 'text.markdown'))

  @info_store.content = Trundle.config.to_h unless exist?

  if block_given?
    yield(self)
    close
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



54
55
56
57
58
59
60
# File 'lib/trundle/text_bundle.rb', line 54

def method_missing(name, *args, &block)
  if Trundle.config.namespace?(name)
    namespaced_attributes_for(name)
  else
    raise Trundle::NamespaceNotDefined, namespace_not_defined_message(name)
  end
end

Instance Method Details

#closeObject



38
39
40
41
42
43
# File 'lib/trundle/text_bundle.rb', line 38

def close
  Dir.mkdir(@path) unless exist?
  write_namespaces
  @info_store.write
  @text_store.write
end

#exist?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/trundle/text_bundle.rb', line 26

def exist?
  File.exist?(@path)
end

#textObject



30
31
32
# File 'lib/trundle/text_bundle.rb', line 30

def text
  @text_store.content
end

#text=(value) ⇒ Object



34
35
36
# File 'lib/trundle/text_bundle.rb', line 34

def text=(value)
  @text_store.content = value
end

#transient=(value) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
# File 'lib/trundle/text_bundle.rb', line 45

def transient=(value)
  raise ArgumentError, 'transient must be a boolean' unless !!value == value
  info['transient'] = value
end

#transient?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/trundle/text_bundle.rb', line 50

def transient?
  !!info['transient']
end