Sha256: 42a9829d80d6bf6bc7d6d9d3bc9e98cc2e80f2981bf91e8635e0ef4268b55396

Contents?: true

Size: 777 Bytes

Versions: 30

Compression:

Stored size: 777 Bytes

Contents

# frozen_string_literal: true

class CategoryDao
  attr_reader :k_builder
  attr_reader :load_time
  attr_reader :data

  def initialize(k_builder)
    @k_builder = k_builder
    @load_time = nil
    @data = nil
  end

  def file_name
    k_builder.target_folders.join(:builder_data, 'categories.json')
  end

  def reload?
    @load_time.nil? || @load_time < File.mtime(file_name)
  end

  def find_category(name)
    result = categories.find { |category| category[:name] == name.to_s }

    raise "Category #{name} not found" if result.nil?

    result
  end

  def categories
    if reload?
      @data = JSON.parse(File.read(file_name), symbolize_names: true)
      @categories = data[:categories]
      @load_time = File.mtime(file_name)
    end
    @categories
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
cmdlet-0.14.0 .builders/director/category_dao.rb
cmdlet-0.13.2 .builders/director/category_dao.rb
cmdlet-0.13.1 .builders/director/category_dao.rb
cmdlet-0.13.0 .builders/director/category_dao.rb
cmdlet-0.12.5 .builders/director/category_dao.rb
cmdlet-0.12.4 .builders/director/category_dao.rb
cmdlet-0.12.3 .builders/director/category_dao.rb
cmdlet-0.12.2 .builders/director/category_dao.rb
cmdlet-0.12.1 .builders/director/category_dao.rb
cmdlet-0.12.0 .builders/director/category_dao.rb
cmdlet-0.11.0 .builders/director/category_dao.rb
cmdlet-0.10.1 .builders/director/category_dao.rb
cmdlet-0.10.0 .builders/director/category_dao.rb
cmdlet-0.9.2 .builders/director/category_dao.rb
cmdlet-0.9.1 .builders/director/category_dao.rb
cmdlet-0.9.0 .builders/director/category_dao.rb
cmdlet-0.8.0 .builders/director/category_dao.rb
cmdlet-0.7.1 .builders/director/category_dao.rb
cmdlet-0.7.0 .builders/director/category_dao.rb
cmdlet-0.6.2 .builders/director/category_dao.rb