Class: PaspagonConfig
- Inherits:
-
Object
- Object
- PaspagonConfig
- Defined in:
- lib/jekyll-paspagon/config.rb
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#full_config ⇒ Object
readonly
Returns the value of attribute full_config.
Instance Method Summary collapse
- #bucket_dest_dir(bucket_name) ⇒ Object
- #bucket_name(post) ⇒ Object
- #format_configs(post) ⇒ Object
-
#initialize(site) ⇒ PaspagonConfig
constructor
A new instance of PaspagonConfig.
- #logging_bucket_name ⇒ Object
- #paid_dest_dir ⇒ Object
- #post_config_complete(post) ⇒ Object
- #write_buckets_config ⇒ Object
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
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
5 6 7 |
# File 'lib/jekyll-paspagon/config.rb', line 5 def buckets @buckets end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
5 6 7 |
# File 'lib/jekyll-paspagon/config.rb', line 5 def formats @formats end |
#full_config ⇒ Object (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_name ⇒ Object
55 56 57 |
# File 'lib/jekyll-paspagon/config.rb', line 55 def logging_bucket_name @full_config['logging_bucket'] end |
#paid_dest_dir ⇒ Object
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_config ⇒ Object
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 |