Class: Trundle::TextBundle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InfoAccessors

info_accessors

Constructor Details

#initialize(path) ⇒ TextBundle

Returns a new instance of TextBundle.



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

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'))
  @asset_store = Trundle::AssetStore.new(File.join(@path, 'assets'))

  @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



60
61
62
63
64
65
66
# File 'lib/trundle/text_bundle.rb', line 60

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 Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/trundle/text_bundle.rb', line 4

def path
  @path
end

Instance Method Details

#assetsObject



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

def assets
  @asset_store
end

#closeObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/trundle/text_bundle.rb', line 28

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

#textObject



32
33
34
# File 'lib/trundle/text_bundle.rb', line 32

def text
  @text_store.content
end

#text=(value) ⇒ Object



36
37
38
# File 'lib/trundle/text_bundle.rb', line 36

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

#transient=(value) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#transient?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/trundle/text_bundle.rb', line 56

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