pennylane 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b079bfa7d777a0adb18de2cb8b02c4b5b3f7a20ef14ee3be35ccc56c4fc5714
4
- data.tar.gz: 417d611044b5329eb04040ffaab0c1e78e609b6dc5613deeeac35994aab88012
3
+ metadata.gz: c2e821259dc8683a82dd041e681f09c8eee4982f0a945c830709a7dca9409e72
4
+ data.tar.gz: f7a0db763e780102951c050aaca06bcb8c178dbc3524defdaf4cd3389f982733
5
5
  SHA512:
6
- metadata.gz: 8d1e5ec1c7aacb11921d8d7490c8bfcfd626fb185a74c6199b1ac9b75e4b4cae03dc8f66be2e70effada0cc21a1d563b1aef205beca5d906bc522637d76b429c
7
- data.tar.gz: fbec4d19969a69390de3903fcb7a1e9e372fcdc4d6bb9b3f735ac09e3a31b7bbea14963e0e35d0c0815d42140385e168e21f21e764caae06d6fdbea08ebec21c
6
+ metadata.gz: 3f2f0dd8084a8017e40e463f70c9664e0cf684f9e656da437edcb48f30c429a827f38412ff93d61675faf31e56063d88d1ad8bac688a392789d586defd6833b5
7
+ data.tar.gz: e3745c63a10ddb89fff5d114bdff477fcd20ac3341ae7c9f44f27175db5a40f823befdcb3c6658aa336b9f71914ff93c17ba3b74f95934208750c32f49f2dc89
data/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
- ## [Unreleased]
1
+ ## [1.0.1] - 2024-04-29
2
+ - Fixed gem initialization issue (resources/*.rb) from a Rails app.
2
3
 
3
4
  ## [1.0.0] - 2024-04-29
4
5
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pennylane (1.0.0)
4
+ pennylane (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -16,9 +16,22 @@ Install the gem and add to the application's Gemfile by executing:
16
16
  $ bundle add pennylane
17
17
 
18
18
  If bundler is not being used to manage dependencies, install the gem by executing:
19
+ ```ruby
20
+ # Add to gemfile
21
+ gem 'pennylane'
22
+ ```
19
23
 
20
- $ gem install pennylane
24
+ For Rails app :
25
+ ```ruby
26
+ # Create initializers/pennylane.rb
27
+ Pennylane.api_key = Rails.application.credentials.dig(:pennylane, :api_key)
21
28
 
29
+ # Add credentials to config/credentials.yml.enc
30
+ $ EDITOR=vim bin/rails credentials:edit
31
+
32
+ pennylane:
33
+ api_key: 'x0fd....'
34
+ ```
22
35
  ## Requirements
23
36
  Ruby 2.3+.
24
37
 
@@ -19,7 +19,7 @@ module Pennylane
19
19
  end
20
20
 
21
21
  def key_for(resp)
22
- resp.keys.find { |k| Pennylane::API_RESOURCES.keys.include?(Util.singularize(k.to_s)) } || resp.keys.find { |k| resp[k].is_a? Array }
22
+ resp.keys.find { |k| Pennylane::ObjectTypes.object_names_to_classes.keys.include?(Util.singularize(k.to_s)) } || resp.keys.find { |k| resp[k].is_a? Array }
23
23
  end
24
24
 
25
25
  end
@@ -0,0 +1,15 @@
1
+ module Pennylane
2
+ module ObjectTypes
3
+ def self.object_names_to_classes
4
+ {
5
+ ListObject.object_name => ListObject,
6
+ Category.object_name => Category,
7
+ CategoryGroup.object_name => CategoryGroup,
8
+ Customer.object_name => Customer,
9
+ CustomerInvoice.object_name => CustomerInvoice,
10
+ Product.object_name => Product,
11
+ Supplier.object_name => Supplier
12
+ }.freeze
13
+ end
14
+ end
15
+ end
@@ -74,7 +74,7 @@ module Pennylane
74
74
  # So we can call directly method on the object rather than going through his key
75
75
  # Pennylane::Customer.retrieve('any-id').name == Pennylane::Customer.retrieve('any-id').customer.name
76
76
  def method_missing(method_name, *args, &block)
77
- raise NoMethodError, "undefined method `#{method_name}` for #{self.class}" unless object
77
+ raise NoMethodError, "undefined method `#{method_name}` for #{self.class}.\nMethods available : #{@values.keys}" unless object
78
78
  object.send(method_name, *args, &block)
79
79
  end
80
80
 
@@ -32,7 +32,6 @@ module Pennylane
32
32
  # Since we don't have the ability to change the API response.
33
33
  # We can achieve this by calling normalize_response(response, with: {invoice: 'customer_invoice'})
34
34
  def normalize_response(object, with={})
35
- # puts object.inspect
36
35
  case object
37
36
  when Hash
38
37
  new_hash = {}
@@ -85,7 +84,7 @@ module Pennylane
85
84
  end
86
85
 
87
86
  def klass_for(object)
88
- Pennylane::API_RESOURCES[singularize(object)] || Pennylane::Object
87
+ Pennylane::ObjectTypes.object_names_to_classes[singularize(object)] || Pennylane::Object
89
88
  rescue
90
89
  Pennylane::Object
91
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pennylane
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/pennylane.rb CHANGED
@@ -11,8 +11,9 @@ require 'forwardable'
11
11
  require 'uri'
12
12
  require 'net/http'
13
13
 
14
- Dir["./lib/pennylane/resources/*.rb"].each {|file| require file }
14
+ Dir[File.join(__dir__, 'pennylane/resources/*.rb')].each {|file| require file }
15
15
 
16
+ require 'pennylane/object_types'
16
17
 
17
18
  module Pennylane
18
19
  class Error < StandardError; end
@@ -20,16 +21,6 @@ module Pennylane
20
21
  class ConfigurationError < Error; end
21
22
  class NotFoundError < Error; end
22
23
 
23
- API_RESOURCES = {
24
- ListObject.object_name => ListObject,
25
- Category.object_name => Category,
26
- CategoryGroup.object_name => CategoryGroup,
27
- Customer.object_name => Customer,
28
- CustomerInvoice.object_name => CustomerInvoice,
29
- Product.object_name => Product,
30
- Supplier.object_name => Supplier
31
- }.freeze
32
-
33
24
  @config = Pennylane::Configuration.new
34
25
  # So we can have a module Pennylane that can be a class as well Pennylane.api_key = '1234'
35
26
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pennylane
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephane Bounmy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vcr
@@ -87,6 +87,7 @@ files:
87
87
  - lib/pennylane/configuration.rb
88
88
  - lib/pennylane/list_object.rb
89
89
  - lib/pennylane/object.rb
90
+ - lib/pennylane/object_types.rb
90
91
  - lib/pennylane/resources/base.rb
91
92
  - lib/pennylane/resources/category.rb
92
93
  - lib/pennylane/resources/category_group.rb