Class: Codestrap::Object::Standard::Files

Inherits:
Abstract
  • Object
show all
Defined in:
lib/codestrap/object/standard/files.rb

Overview

Static file derived objects

Create objects from .json, .yaml and executable files

Class Method Summary collapse

Class Method Details

.objectsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/codestrap/object/standard/files.rb', line 17

def objects
  objects = {}

  glob_array = Array(Files.dirs).map { |file| File.join(File.expand_path(file), '*') }
  Codestrap::Patch::Dir.glob_files(glob_array).each do |file|
    stat = File::Stat.new file
    name = File.basename(file, File.extname(file)).downcase
    case
      when /\.json$/.match(file)
        objects[name] = JSON.load(File.read(file))
      when /\.yaml$/.match(file)
        objects[name] = YAML.load(File.read(file))
      when stat.executable?
        objects[name] = JSON.parse(`#{file}`)
    end
  end

  objects
end

.weightInteger

Object(s) weight

Returns:

  • (Integer)


13
14
15
# File 'lib/codestrap/object/standard/files.rb', line 13

def weight
  100
end