Sha256: fb7b212edca0c9a28c2b5749b4be31e35454bce383ab5b5e40c8641b9c8c2ec4

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'active_model'
require 'inifile'
require 'firebrew/firefox/extension'

module Firebrew::Firefox
  class Profile
    include ActiveModel::Model
    
    class Manager
      def initialize(params={})
        @base_dir = params[:base_dir]
        @data_file = params[:data_file] || 'profiles.ini'
        raise Firebrew::ProfilesFileNotFoundError unless File.exists? self.data_path
      end
      
      def all
        sections = IniFile.load(self.data_path).to_h
        profiles = sections.find_all{|(name,prop)| name.match(/^Profile\d+$/)}
        profiles.map do |(name,prop)|
          Profile.new(
            name: prop['Name'],
            path: self.profile_path(prop['Path'], prop['IsRelative'] == '1'),
            is_default: prop['Default'] == '1',
          )
        end
      end
      
      def find(name)
        self.all.find{|p| p.name == name }
      end
      
      def find!(name)
        result = self.find(name)
        raise Firebrew::ProfileNotFoundError if result.nil?
        result
      end
      
      protected
      
      def data_path
        File.expand_path File.join(@base_dir, @data_file)
      end
      
      def profile_path(path, is_relative)
        path = is_relative ? File.join(@base_dir, path) : path 
        File.expand_path path
      end
    end
    
    attr_accessor :name, :path, :is_default
    
    def extensions
      Extension::Manager.new(profile: self)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
firebrew-0.1.3 lib/firebrew/firefox/profile.rb
firebrew-0.1.2 lib/firebrew/firefox/profile.rb
firebrew-0.1.1 lib/firebrew/firefox/profile.rb
firebrew-0.1.0 lib/firebrew/firefox/profile.rb