Sha256: f243d003b846d02a89fa5909dc0c75ca308f0cb742f8cc900c7e65818149f452

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

module Troo
  class Preference
    include Virtus.value_object

    values do
      attribute :label, String
      attribute :value, String
    end

    class << self
      def view(parameters)
        new(parameters).view
      end
    end

    def view
      [formatted_label, value].join(' ')
    end

    private

    def formatted_label
      (label + ':').rjust(25, ' ')
    end
  end

  class Configuration
    include Virtus.value_object

    values do
      attribute :api_url
      attribute :api_key
      attribute :api_token
      attribute :api_oauth_token
      attribute :api_oauth_token_secret
      attribute :database
      attribute :allow_remote, Boolean, default: true
      attribute :logs,         Boolean, default: false
    end

    class << self
      def load(file, env)
        new(YAML.load_file(file)[env.to_s])
      end
    end

    def view
      attributes.map do |label, value|
        Preference.view(label: label, value: value)
      end.join("\n")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.9 lib/troo/configuration.rb