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 +4 -4
- data/.travis.yml +4 -1
- data/lib/pupper/api_associations.rb +4 -2
- data/lib/pupper/model.rb +7 -16
- data/lib/pupper/version.rb +1 -1
- data/pupper.gemspec +3 -0
- metadata +43 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dd8e6ae57ca9a19f554152de9ff756bf1de5744
|
4
|
+
data.tar.gz: 307eb48942bcaf2494b27908f694048c093b318a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eec15f8a5eff6ce57082e530b6f3df263c889fc688331a532b1381c14cc9d1438063a8248b1377f99215b4032362ba716d41b215b1a66e27e583d5ebb15a3b4
|
7
|
+
data.tar.gz: 292a88af0c52aa174a0fb9e70873783760537ae495b1bc73086110bff088eb5a6b72f37df8d01f0fbb0b75f976904ed2327d4348c24db9c6baf6da572bbc7010
|
data/.travis.yml
CHANGED
@@ -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
|
-
|
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
|
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
|
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
|
55
|
+
# @overload backend=(class_or_symbol)
|
56
56
|
# Declare whether or not the model has a corresponding API client or not.
|
57
|
-
# (default: `
|
57
|
+
# (default: including class, plural, + client, e.g. `Form` => `FormsClient`)
|
58
58
|
#
|
59
59
|
# == Parameters:
|
60
|
-
#
|
61
|
-
# `
|
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
|
data/lib/pupper/version.rb
CHANGED
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.
|
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
|