Sha256: 24633af8675c72cb4b8b428ae688da02f37f9115a97bedd4658d66412c46c1c1

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

module Troo
  class Configuration
    include Virtus.model

    attribute :api_key
    attribute :api_token
    attribute :api_oauth_token
    attribute :api_oauth_token_secret
    attribute :allow_remote, Boolean, default: true
    attribute :logs,         Boolean, default: false
    attribute :name,         String,  default: 'My Default Configuration'
    attribute :api_url,      String,  default: 'https://api.trello.com/1'
    attribute :database,     Integer, default: 1

    class << self
      # @param  [String]
      # @param  [String]
      # @return [Troo::Configuration]
      def load(file, env)
        new(YAML.load_file(file)[env])
      end
    end

    # @param  [String]
    # @param  [String]
    # @return [TrueClass, FalseClass]
    def save(file, env)
      return true if File.open(file, 'w') do |file|
        file.write configuration_yaml(env)
      end
      false
    end

    # @return [String]
    def view
      attributes.map do |label, value|
        Preference.view(label: label, value: value)
      end.join("\n")
    end

    private

    def configuration_yaml(env = 'default')
      { env => self.attributes }.to_yaml
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
troo-0.0.15 lib/troo/configuration.rb
troo-0.0.14 lib/troo/configuration.rb
troo-0.0.13 lib/troo/configuration.rb
troo-0.0.12 lib/troo/configuration.rb