unit4-checkout 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86c9a4b5ced5591d1e29fab651f213c6b2650bb4704e11635161b3af16076442
4
- data.tar.gz: 015c9dcccbc32478e8ac41875d506588c1319835a57764e985d1cb4140396bcc
3
+ metadata.gz: 83982e7ddae1c09934ca1125ae9cfb0b0b8b845638fbce0eb19472137057652b
4
+ data.tar.gz: fb8982c906834e642dcaedbd81cdb89f258555c1dcbab7f73dc1387a9cd609fa
5
5
  SHA512:
6
- metadata.gz: 9918c0698cae46a2e02bf767b000a4da06173a023f72b8bae9d4694d09e6b3a92e0a2b1fbceaab4438635253a2bc3a5f9e198f1c6d4079ef8dc9567c174f1aea
7
- data.tar.gz: e511b5b0a2ddf526f51ee5adbbece0c8ba91642203a18ba806100f8c4348e76f6c5218fbb21c31ba2dce68703723b7bd94da078d2fbfdb7adcb8182609bca0c0
6
+ metadata.gz: 514d5a25a55f090eb87ebcd5d49ce013b7638efa885e79dd59270c361bcb0462f929140706413d04624a5bfdfdad757f07648dc8403f188d72b07fe36b48bee3
7
+ data.tar.gz: 1721ec7136a1c447903ffbfdbad3ce2c7d0fea7ff11c19eed5ca57a5adfcdd3895b16d930d3a34a910dfd2a21ccf5dc08cf7d200f2945872ceb80502fa74b4da
data/Gemfile CHANGED
@@ -14,5 +14,3 @@ gem "rubocop", "~> 1.21"
14
14
  gem "activerecord"
15
15
 
16
16
  gem "erb"
17
-
18
- # gem "sqlite3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unit4-checkout (0.1.0)
4
+ unit4-checkout (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,7 +4,7 @@ require "active_record"
4
4
  require "erb"
5
5
 
6
6
  class Checkout
7
- attr_reader :promotional_rules, :total, :basket, :price_discount_applied_flag
7
+ attr_reader :promotional_rules, :total, :basket, :price_discount_applied_flag, :result
8
8
 
9
9
  # {product_discounts: {001: {count:2, price: 3.25}, 004: {count:2, price: 3.25}}, total_price_discount: $50}
10
10
  def initialize(promotional_rules)
@@ -27,7 +27,8 @@ class Checkout
27
27
  end
28
28
 
29
29
  def calculate_total(item)
30
- item_price = find_item_price(item)
30
+ find_item_price(item)
31
+ item_price = 3
31
32
  new_discount_available?(item) ? apply_discounts : @total += item_price
32
33
  @total
33
34
  end
@@ -36,7 +37,6 @@ class Checkout
36
37
  query = "SELECT * FROM 'users' WHERE 'users'.'id' = ?"
37
38
  sanitized_query = ActiveRecord::Base.sanitize_sql_array([query, item])
38
39
  execute_statement(sanitized_query)
39
- ActiveRecord::Base.connection.exec_query(sanitized_query)
40
40
  end
41
41
 
42
42
  def apply_discounts; end
@@ -45,7 +45,7 @@ class Checkout
45
45
 
46
46
  def execute_statement(sql)
47
47
  results = ActiveRecord::Base.connection.exec_query(sql)
48
- results if results.present?
48
+ @result = results if results.present?
49
49
  end
50
50
 
51
51
  def establish_connection
@@ -54,12 +54,16 @@ class Checkout
54
54
  end
55
55
 
56
56
  def setup_db_config
57
- if defined? Rails && defined? Rails.env
58
- Rails.application.config.database_configuration[Rails.env]
59
- else
60
- # TODO: use current database instead of development
61
- YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, aliases: true)["development"]
62
- end
57
+ defined?(Rails) && defined?(Rails.env) ? rails_db_config : non_rails_db_config
58
+ end
59
+
60
+ def rails_db_config
61
+ Rails.application.config.database_configuration[Rails.env]
62
+ end
63
+
64
+ def non_rails_db_config
65
+ # TODO: use current database instead of development
66
+ YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, aliases: true)["development"]
63
67
  end
64
68
 
65
69
  # maybe add remove item function
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unit4
4
4
  module Checkout
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unit4-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boyan Georgiev