Sha256: 1ae3f6f8376726901d4512a96775b279ac5b1ddbf2d2cab54d20d72448e92fb5

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

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 :name
      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])
      rescue Errno::ENOENT
        puts "\nConfiguration cannot be found, please run 'troo init'" \
             " first.\n\n"
        exit(1)
      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.10 lib/troo/configuration.rb