Class: PaspagonConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-paspagon/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ PaspagonConfig

Returns a new instance of PaspagonConfig.



7
8
9
10
11
12
13
14
# File 'lib/jekyll-paspagon/config.rb', line 7

def initialize(site)
  @site = site
  @full_config = site.config['paspagon'] || {}
  @terms_accepted = @full_config['accept-terms'] == 'https://github.com/Paspagon/paspagon.github.io/blob/master/terms-seller.md'
  raise 'Paspagon terms not accepted' unless @terms_accepted
  @buckets = @full_config['buckets'] || {}
  @formats = @full_config['formats'] || {}
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



5
6
7
# File 'lib/jekyll-paspagon/config.rb', line 5

def buckets
  @buckets
end

#formatsObject (readonly)

Returns the value of attribute formats.



5
6
7
# File 'lib/jekyll-paspagon/config.rb', line 5

def formats
  @formats
end

#full_configObject (readonly)

Returns the value of attribute full_config.



5
6
7
# File 'lib/jekyll-paspagon/config.rb', line 5

def full_config
  @full_config
end

Instance Method Details

#bucket_dest_dir(bucket_name) ⇒ Object



36
37
38
# File 'lib/jekyll-paspagon/config.rb', line 36

def bucket_dest_dir(bucket_name)
  File.join(paid_dest_dir, bucket_name)
end

#bucket_name(post) ⇒ Object



21
22
23
24
25
26
# File 'lib/jekyll-paspagon/config.rb', line 21

def bucket_name(post)
  bucket = post.data['bucket']
  raise 'Bucket not specified for post' unless bucket
  raise "Bucket not found: #{bucket}" unless @buckets.key?(bucket)
  bucket
end

#format_configs(post) ⇒ Object



28
29
30
# File 'lib/jekyll-paspagon/config.rb', line 28

def format_configs(post)
  @formats.merge(post.data['formats'] || {})
end

#logging_bucket_nameObject



55
56
57
# File 'lib/jekyll-paspagon/config.rb', line 55

def logging_bucket_name
  @full_config['logging_bucket']
end


32
33
34
# File 'lib/jekyll-paspagon/config.rb', line 32

def paid_dest_dir
  File.join(@site.dest, '../_paid')
end

#post_config_complete(post) ⇒ Object



16
17
18
19
# File 'lib/jekyll-paspagon/config.rb', line 16

def post_config_complete(post)
  payment_config = full_payment_config post
  prices(payment_config) && addresses(payment_config)
end

#write_buckets_configObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jekyll-paspagon/config.rb', line 40

def write_buckets_config
  @buckets.each do |bucket_name, bucket_hash|
    bucket_config = bucket_hash.update('accept-terms' => @full_config['accept-terms'])
    ini = hash_to_ini bucket_config
    bucket_dest_dir = bucket_dest_dir(bucket_name)
    FileUtils.mkdir_p(bucket_dest_dir)
    dest = File.join(bucket_dest_dir, 'paspagon.ini')
    ini_hash = Digest::SHA256.digest(ini)
    next if File.exist?(dest) && Digest::SHA256.file(dest).digest == ini_hash
    File.open(dest, 'wb') do |f|
      f.write(ini)
    end
  end
end