Class: Frontman::DataStoreFile

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/frontman/data_store_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, file_name, base_file_name, parent) ⇒ DataStoreFile

Returns a new instance of DataStoreFile.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/frontman/data_store_file.rb', line 22

def initialize(path, file_name, base_file_name, parent)
  @path = path
  @file_name = file_name
  @base_file_name = base_file_name
  @parent = parent
  @data = (YAML.load_file(@path) || {}).to_ostruct

  @@i ||= 0
  @position = @@i
  @@i += 1
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments, &block) ⇒ Object



34
35
36
# File 'lib/frontman/data_store_file.rb', line 34

def method_missing(method_id, *arguments, &block)
  @data.public_send(method_id, *arguments, &block)
end

Instance Attribute Details

#base_file_nameObject

Returns the value of attribute base_file_name.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def base_file_name
  @base_file_name
end

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def data
  @data
end

#file_nameObject

Returns the value of attribute file_name.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def file_name
  @file_name
end

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def path
  @path
end

#positionObject

Returns the value of attribute position.



11
12
13
# File 'lib/frontman/data_store_file.rb', line 11

def position
  @position
end

Instance Method Details

#current_pathObject



43
44
45
# File 'lib/frontman/data_store_file.rb', line 43

def current_path
  @path
end

#refreshObject



48
49
50
51
52
53
# File 'lib/frontman/data_store_file.rb', line 48

def refresh
  return unless Frontman::App.instance.refresh_data_files

  data = YAML.load_file(@path) || {}
  @data = data.to_ostruct
end

#respond_to_missing?(method_id, _) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/frontman/data_store_file.rb', line 38

def respond_to_missing?(method_id, _)
  @data.respond_to? method_id
end

#to_ostructObject



61
62
63
# File 'lib/frontman/data_store_file.rb', line 61

def to_ostruct
  self
end

#to_sObject



56
57
58
# File 'lib/frontman/data_store_file.rb', line 56

def to_s
  "<DataStoreFile #{@data.keys.join(', ')} >"
end