pupper 0.1.7 → 0.1.8

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
  SHA1:
3
- metadata.gz: 691ae8c03c3853270c769eeb8f2843c58fd35e69
4
- data.tar.gz: 1226c5952381f25be872736d53c46b8f5f77c4ea
3
+ metadata.gz: 7dd8e6ae57ca9a19f554152de9ff756bf1de5744
4
+ data.tar.gz: 307eb48942bcaf2494b27908f694048c093b318a
5
5
  SHA512:
6
- metadata.gz: 21197fda988bfd1f751c54a56ac3fd22d871fcb1bbf883992edfa3d92ac9363348bb8e2dcc056339536dc0c130ffaeb06db0176c29e7c3f41817c2acf3c66376
7
- data.tar.gz: eb940c6c849d64ac3062a3479201a55e288230007d83cd52bf24084df55bb778d6d6750f1d876914a4c45b5de18ca1f8389242a882de63267ccb87e24c4f4959
6
+ metadata.gz: 9eec15f8a5eff6ce57082e530b6f3df263c889fc688331a532b1381c14cc9d1438063a8248b1377f99215b4032362ba716d41b215b1a66e27e583d5ebb15a3b4
7
+ data.tar.gz: 292a88af0c52aa174a0fb9e70873783760537ae495b1bc73086110bff088eb5a6b72f37df8d01f0fbb0b75f976904ed2327d4348c24db9c6baf6da572bbc7010
data/.travis.yml CHANGED
@@ -2,4 +2,7 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.4.0
5
- before_install: gem install bundler -v 1.14.3
5
+ before_install:
6
+ - gem install bundler -v 1.14.3
7
+ script:
8
+ - bundle exec rspec
@@ -35,6 +35,8 @@ module Pupper
35
35
  def create_attribute(name, foreign_key = nil, value = nil)
36
36
  self.class.attr_accessor(name)
37
37
  excluded_attrs << name if foreign_key.present?
38
+
39
+ name = foreign_key.present? ? "#{name}_#{foreign_key}" : name
38
40
  send("#{name}=", value)
39
41
  end
40
42
 
@@ -56,7 +58,8 @@ module Pupper
56
58
 
57
59
  def create_has_many_assoc_model(name, values)
58
60
  create_attribute(name)
59
- values.map(&name.constantize)
61
+ model = "#{self.class.parent}/#{name.to_s.singularize}".classify.constantize
62
+ values.map(&model.method(:new))
60
63
  end
61
64
 
62
65
  def create_assoc_model(assocs, name, foreign_key, value)
@@ -66,7 +69,6 @@ module Pupper
66
69
  when :has_many
67
70
  assocs[name] = create_has_many_assoc_model(name, value)
68
71
  else
69
- Rails.logger.warn("Try to use an association for #{name} in #{model_name.name}!")
70
72
  assocs[:"#{name}_#{foreign_key}"] = value
71
73
  end
72
74
  end
data/lib/pupper/model.rb CHANGED
@@ -20,7 +20,7 @@ module Pupper
20
20
 
21
21
  def initialize(**args)
22
22
  assocs, attrs = args.partition do |attr, value|
23
- attr.to_s =~ /_u?id$/ || value.is_a?(Hash)
23
+ attr.to_s =~ /_u?id$/ || value.is_a?(Hash) || value.is_a?(Array)
24
24
  end.map(&Hash.method(:[]))
25
25
 
26
26
  assocs = build_associations(assocs)
@@ -29,7 +29,7 @@ module Pupper
29
29
 
30
30
  changes_applied
31
31
 
32
- backend.register_model(self) unless static?
32
+ backend.register_model(self) unless backend == :none
33
33
  end
34
34
 
35
35
  def primary_key
@@ -38,7 +38,7 @@ module Pupper
38
38
  end
39
39
 
40
40
  class_methods do
41
- attr_writer :primary_key, :backend, :static
41
+ attr_writer :primary_key, :backend
42
42
 
43
43
  # @overload primary_key=(identifier)
44
44
  # Set the identifier the including model will use by default
@@ -52,27 +52,18 @@ module Pupper
52
52
  @primary_key ||= :uid
53
53
  end
54
54
 
55
- # @overload static=(true_or_false)
55
+ # @overload backend=(class_or_symbol)
56
56
  # Declare whether or not the model has a corresponding API client or not.
57
- # (default: `false`)
57
+ # (default: including class, plural, + client, e.g. `Form` => `FormsClient`)
58
58
  #
59
59
  # == Parameters:
60
- # true_or_false::
61
- # `true` if the model has no API, `false` otherwise.
62
- def static?
63
- @static ||= false
64
- end
65
-
60
+ # class_or_symbol::
61
+ # `:none` if the model has no API, constant otherwise.
66
62
  def backend
67
- return if static?
68
63
  @backend ||= "#{model_name.name.pluralize}Client".constantize.new
69
64
  end
70
65
  end
71
66
 
72
- def static?
73
- self.class.static?
74
- end
75
-
76
67
  def to_json(*)
77
68
  attributes.except(*excluded_attrs).to_json
78
69
  end
@@ -1,3 +1,3 @@
1
1
  module Pupper
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/pupper.gemspec CHANGED
@@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.14'
24
+ spec.add_development_dependency 'byebug'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
25
26
  spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'pry-byebug'
26
29
 
27
30
  spec.add_dependency 'activesupport', '~> 5.0'
28
31
  spec.add_dependency 'activemodel', '~> 5.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pupper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Machin
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: activesupport
57
99
  requirement: !ruby/object:Gem::Requirement