Class: Passbook::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/passbook/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enable_routesObject

Returns the value of attribute enable_routes.



25
26
27
# File 'lib/passbook/config.rb', line 25

def enable_routes
  @enable_routes
end

#pass_configObject

Returns the value of attribute pass_config.



25
26
27
# File 'lib/passbook/config.rb', line 25

def pass_config
  @pass_config
end

#preload_templateObject

Returns the value of attribute preload_template.



25
26
27
# File 'lib/passbook/config.rb', line 25

def preload_template
  @preload_template
end

#wwdr_certificateObject

Returns the value of attribute wwdr_certificate.



25
26
27
# File 'lib/passbook/config.rb', line 25

def wwdr_certificate
  @wwdr_certificate
end

#wwdr_intermediate_certificate_pathObject

Returns the value of attribute wwdr_intermediate_certificate_path.



25
26
27
# File 'lib/passbook/config.rb', line 25

def wwdr_intermediate_certificate_path
  @wwdr_intermediate_certificate_path
end

Instance Method Details

#add_pkpass {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
38
39
# File 'lib/passbook/config.rb', line 33

def add_pkpass
  self.pass_config = Hash.new unless self.pass_config
  yield self
  self.preload_template ||= ::Rails.env.production? if defined? ::Rails
  read_templates if self.preload_template
  read_p12_certificates
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
# File 'lib/passbook/config.rb', line 27

def configure
  self.pass_config = Hash.new unless self.pass_config
  yield self
  read_wwdr_certificate
end

#load_files(path) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/passbook/config.rb', line 48

def load_files path
  files = {}
  Dir.glob(path+"/**/**").each do |file_path|
    next if File.directory? file_path
    filename = Pathname.new(file_path).relative_path_from(Pathname.new(path))
    file = File.open(file_path, "rb")
    files[filename.to_s] = File.read(file)
  end
  files
end

#read_p12_certificatesObject



59
60
61
62
63
64
65
# File 'lib/passbook/config.rb', line 59

def read_p12_certificates
  pass_config.each do |pass_type_id, config|
    raise(ArgumentError, "Please specify cert_path (certificate path) in your configuration (in initializer)") unless config['cert_path'] && !config['cert_path'].blank?
    raise(ArgumentError, "Please specify cert_password (certificate password) in your configuration (in initializer)") unless config['cert_password']
    config['p12_certificate'] ||=  OpenSSL::PKCS12::new(File.read(config['cert_path']), config['cert_password'])
  end
end

#read_templatesObject



41
42
43
44
45
46
# File 'lib/passbook/config.rb', line 41

def read_templates
  self.pass_config.each do |pass_type_id, config|
    raise(ArgumentError, "Please specify a template_path in your configuration (in initializer)") unless config['template_path']
    config['files']||= load_files config['template_path']
  end
end

#read_wwdr_certificateObject



67
68
69
70
# File 'lib/passbook/config.rb', line 67

def read_wwdr_certificate
  # raise(ArgumentError, "Please specify the WWDR Intermediate certificate in your initializer") unless self.wwdr_intermediate_certificate_path
  self.wwdr_certificate||= OpenSSL::X509::Certificate.new(File.read(self.wwdr_intermediate_certificate_path))
end