Module: Faalis::Generators::Concerns::InputFile

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/input_file.rb

Overview

This module Provide an argument for generator which is needed by other Concerns. Each Concern will have its own entry in scaffold json file. For documentation on each entry checkout its concern class

Instance Method Summary (collapse)

Instance Method Details

- (Object) extname (private)

Get the extension name of input file



25
26
27
# File 'lib/faalis/generators/concerns/input_file.rb', line 25

def extname
  File.extname(file_path)
end

- (Object) file_path (private)

Return absolute path to input file



21
22
23
# File 'lib/faalis/generators/concerns/input_file.rb', line 21

def file_path
  File.expand_path(input_file)
end

- (Object) input_file_data (private)

Read the json or yaml file and returns its raw data



30
31
32
# File 'lib/faalis/generators/concerns/input_file.rb', line 30

def input_file_data
  File.read(file_path)
end

- (Object) resource_data (private)

Return the hash related to json or yaml structure from cache or by reading file.



36
37
38
39
40
41
42
43
44
# File 'lib/faalis/generators/concerns/input_file.rb', line 36

def resource_data
  if @data
    @data
  else
    @data = JSON.parse(input_file_data) if extname == '.json'
    @data = YAML.load_file(file_path) if extname == '.yml'
    @data
  end
end