logical_model 0.6.0 → 0.6.1
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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/lib/logical_model.rb
CHANGED
@@ -52,7 +52,7 @@ require 'logical_model/cache'
|
|
52
52
|
# RemoteResource#destroy
|
53
53
|
class LogicalModel
|
54
54
|
extend ActiveModel::Callbacks
|
55
|
-
define_model_callbacks :create, :save, :update, :destroy, :initialize
|
55
|
+
define_model_callbacks :create, :save, :update, :destroy, :initialize, :new_nested
|
56
56
|
|
57
57
|
include LogicalModel::Hydra
|
58
58
|
include LogicalModel::ResponsesConfiguration
|
@@ -62,7 +62,6 @@ class LogicalModel
|
|
62
62
|
include LogicalModel::ApiKey
|
63
63
|
include LogicalModel::SafeLog
|
64
64
|
include LogicalModel::Associations
|
65
|
-
include LogicalModel::Cache
|
66
65
|
|
67
66
|
# include ActiveModel Modules that are usefull
|
68
67
|
extend ActiveModel::Naming
|
@@ -93,8 +93,11 @@ class LogicalModel
|
|
93
93
|
define_method "#{association}_attributes=" do |key_attributes|
|
94
94
|
array = []
|
95
95
|
key_attributes.each do |attr_params|
|
96
|
+
clazz_name = attr_params['_type']
|
97
|
+
clazz = clazz_name.blank? ? attr_class : clazz_name.constantize
|
98
|
+
|
96
99
|
attr_params.to_hash.symbolize_keys!
|
97
|
-
array <<
|
100
|
+
array << clazz.new(attr_params)
|
98
101
|
end
|
99
102
|
instance_variable_set("@#{association}", array)
|
100
103
|
end
|
data/logical_model.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "logical_model"
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dwayne Macgowan"]
|
12
|
-
s.date = "2014-
|
12
|
+
s.date = "2014-08-20"
|
13
13
|
s.description = "LogicalModel allows to use a resource as a model. It is based on web presentation http://www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3"
|
14
14
|
s.email = "dwaynemac@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require './lib/logical_model
|
1
|
+
require './lib/logical_model'
|
2
2
|
|
3
3
|
describe LogicalModel::Associations::HasManyKeys do
|
4
4
|
|
5
5
|
describe "when included" do
|
6
6
|
before do
|
7
|
-
class Example
|
8
|
-
include LogicalModel::Associations::HasManyKeys
|
7
|
+
class Example < LogicalModel
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
@@ -17,22 +16,18 @@ describe LogicalModel::Associations::HasManyKeys do
|
|
17
16
|
describe ".has_many" do
|
18
17
|
before do
|
19
18
|
# has_many :items needs Item class
|
20
|
-
class Item
|
21
|
-
|
22
|
-
|
23
|
-
def initialize(attrs={})
|
24
|
-
@example_id = attrs['example_id']
|
25
|
-
@name = attrs['name']
|
26
|
-
end
|
19
|
+
class Item < LogicalModel
|
20
|
+
attribute :name
|
21
|
+
belongs_to :example
|
27
22
|
end
|
28
23
|
|
29
|
-
class
|
30
|
-
|
31
|
-
|
24
|
+
class SpecialItem < LogicalModel
|
25
|
+
attribute :special_attribute
|
26
|
+
belongs_to :example
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
29
|
+
class Example < LogicalModel
|
30
|
+
has_many :items
|
36
31
|
|
37
32
|
def json_root
|
38
33
|
'example'
|
@@ -67,7 +62,6 @@ describe LogicalModel::Associations::HasManyKeys do
|
|
67
62
|
|
68
63
|
describe "adds #association accessor" do
|
69
64
|
before do
|
70
|
-
debugger
|
71
65
|
@e = Example.new(items: [Item.new()])
|
72
66
|
end
|
73
67
|
it "visible at instance" do
|
@@ -94,5 +88,12 @@ describe LogicalModel::Associations::HasManyKeys do
|
|
94
88
|
end
|
95
89
|
end
|
96
90
|
|
91
|
+
describe "when I initialize the has_many item using an extended class it should create the element using the correct class" do
|
92
|
+
it "should build has_many correctly" do
|
93
|
+
@example = Example.new({:items_attributes => [{"_type"=>"SpecialItem", "special_attribute"=>"test", "value"=>"123"}]})
|
94
|
+
@example.items.first.class.should == SpecialItem
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
97
98
|
end
|
98
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logical_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -393,7 +393,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
393
393
|
version: '0'
|
394
394
|
segments:
|
395
395
|
- 0
|
396
|
-
hash: -
|
396
|
+
hash: -769037933
|
397
397
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
398
398
|
none: false
|
399
399
|
requirements:
|