class ComerDeTapas::Subscription

Constants

KEYS

Attributes

email[R]
password[R]
save_path[R]

Public Class Methods

new() click to toggle source
# File lib/comer_de_tapas/subscription.rb, line 5
def initialize
  abort "Please run `comer_de_tapas init` first" unless CREDENTIAL_FILE.exist?

  set_subscription_data if subscription_data_valid?
end

Public Instance Methods

to_h() click to toggle source

@return [Hash] User“s Ruby Tapas credential information

# File lib/comer_de_tapas/subscription.rb, line 12
def to_h
  { email: email, password: password, save_path: save_path }
end

Private Instance Methods

credential_data_valid?(data) click to toggle source

Return true if passed-in data all match criteria. @return [Boolen]

# File lib/comer_de_tapas/subscription.rb, line 42
      def credential_data_valid? data
        data.each do |hash|
          hash.each do |k,v|
            abort <<-MSG unless KEYS.include? k
Probably have a typo in #{CREDENTIAL_FILE}: #{k}
Valid yaml keys: #{KEYS.join(", ")}.
            MSG
            abort "Please fill in #{k} in #{CREDENTIAL_FILE}" unless v
          end
        end

        return true
      end
get_validate(data) click to toggle source

Get credential data from loaded yaml for validation.

# File lib/comer_de_tapas/subscription.rb, line 57
def get_validate data
  data.values.flatten
end
load_credential_data() click to toggle source

Load ~/.rubytapas/.credentials yaml

# File lib/comer_de_tapas/subscription.rb, line 21
def load_credential_data
  require "yaml"
  @credential_yaml ||= YAML.load CREDENTIAL_FILE.read
end
set_subscription_data() click to toggle source

Set subscription data from ~/.rubytapas/.credentials yaml

# File lib/comer_de_tapas/subscription.rb, line 62
def set_subscription_data
  @email     ||= load_credential_data["credentials"][0]["email"]
  @password  ||= load_credential_data["credentials"][1]["password"]
  @save_path ||= load_credential_data["credentials"][2]["save_path"]
end
subscription_data_valid?() click to toggle source

Return true if ~/.rubytapas/.credentials files are filled and correct. @return [Boolen]

# File lib/comer_de_tapas/subscription.rb, line 28
def subscription_data_valid?
  # empty credential file"s size is about 50-55.
  # 65 is when you have a very short email, password, and save_path.
  # So when you filled in data, probably will > 65.
  if CREDENTIAL_FILE.size < 65
    abort "Did you fill in your subscription data in #{CREDENTIAL_FILE}?"
    return false
  end

  credential_data_valid?(get_validate load_credential_data)
end