embark-journey 0.0.7 → 0.0.8
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 903b83a147f53c1efba286cf039543a5c908ad1d
|
4
|
+
data.tar.gz: 0a87f6e082c435ca7f20851b3ec16faa71ce0ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1816e1461c44ffd10324977f097a94c01cc844f26a171c9b84da4ae8e2dd856fefe3c62b1ca1306e7eeb5a9646b084b97cdad9779376c3de293713b2c7295ce
|
7
|
+
data.tar.gz: d987784dae2d9bde8e8738091000d989c9e9aa245029672a545b15d30b3e388e6712e83da3713107663ee186c1ac30a3a265017eba5d1ac82951013752592102
|
data/README.md
CHANGED
@@ -40,6 +40,23 @@ Create your resource models, inheriting from `Journey::Resource`. Under the hood
|
|
40
40
|
end
|
41
41
|
|
42
42
|
|
43
|
+
### Searching
|
44
|
+
|
45
|
+
To perform a text search on a model's attributes:
|
46
|
+
|
47
|
+
User.search('itni')
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
### Embedding associations
|
52
|
+
|
53
|
+
Often you'll want to load associated resources without needing to make additional queries. This can be specified on the `belongs_to` declaration:
|
54
|
+
|
55
|
+
class User < Journey::Resource
|
56
|
+
belongs_to :account, embed: true
|
57
|
+
end
|
58
|
+
|
59
|
+
|
43
60
|
## Contributing
|
44
61
|
|
45
62
|
1. Fork it
|
@@ -131,7 +131,7 @@ module ActiveResource::Associations
|
|
131
131
|
elsif attributes.include?(method_name)
|
132
132
|
attributes[method_name]
|
133
133
|
elsif association_id = send(finder_key)
|
134
|
-
return nil if
|
134
|
+
return nil if association_id.blank?
|
135
135
|
instance_variable_set(ivar_name, association_model.find(association_id))
|
136
136
|
end
|
137
137
|
end
|
@@ -143,9 +143,9 @@ module ActiveResource::Associations
|
|
143
143
|
end
|
144
144
|
|
145
145
|
attr_accessor :embeds
|
146
|
-
def defines_belongs_to_embed(method_name, association_model)
|
146
|
+
def defines_belongs_to_embed(method_name, association_model, foreign_key)
|
147
147
|
self.embeds ||= []
|
148
|
-
self.embeds <<
|
148
|
+
self.embeds << association_model.to_s.underscore
|
149
149
|
end
|
150
150
|
|
151
151
|
def defines_has_many_finder_method(method_name, association_model)
|
@@ -11,7 +11,7 @@ module ActiveResource::Associations::Builder
|
|
11
11
|
reflection = model.create_reflection(self.class.macro, name, options)
|
12
12
|
model.defines_belongs_to_finder_method(reflection.name, reflection.klass, reflection.foreign_key)
|
13
13
|
|
14
|
-
model.defines_belongs_to_embed(reflection.name, reflection.klass) if embed
|
14
|
+
model.defines_belongs_to_embed(reflection.name, reflection.klass, reflection.foreign_key) if embed
|
15
15
|
|
16
16
|
return reflection
|
17
17
|
end
|
data/lib/journey/version.rb
CHANGED
@@ -101,30 +101,30 @@ describe Journey::Resource do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
describe '::Embed' do
|
104
|
-
class
|
104
|
+
class Asset < Journey::Resource
|
105
105
|
end
|
106
106
|
|
107
|
-
class
|
107
|
+
class Fault < Journey::Resource
|
108
108
|
end
|
109
109
|
|
110
|
-
class
|
111
|
-
belongs_to :
|
112
|
-
belongs_to :
|
110
|
+
class Job < Journey::Resource
|
111
|
+
belongs_to :asset, embed: true
|
112
|
+
belongs_to :reported_fault, class_name: 'Fault', embed: true
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'loads an embedded belongs_to association automatically' do
|
116
|
-
|
117
|
-
|
116
|
+
asset = Asset.create name: 'asset'
|
117
|
+
fault = Fault.create name: 'fault'
|
118
118
|
|
119
|
-
|
120
|
-
id =
|
121
|
-
|
119
|
+
job = Job.create name: 'job', asset_id: asset.id, reported_fault_id: fault.id
|
120
|
+
id = job.id
|
121
|
+
job = Job.find(id)
|
122
122
|
|
123
|
-
expect(
|
124
|
-
expect(asset
|
123
|
+
expect(job.attributes['asset']).to eq asset
|
124
|
+
expect(job.asset).to eq asset
|
125
125
|
|
126
|
-
expect(
|
127
|
-
expect(
|
126
|
+
expect(job.attributes['reported_fault']).to eq fault
|
127
|
+
expect(job.reported_fault).to eq fault
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embark-journey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Davey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|