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: d585fc43842f526ac92b7baa33dfcc5b291bb7c5
4
- data.tar.gz: b2d12857cb32c3f87b3c60fbf8bbe93b27a2fa60
3
+ metadata.gz: 903b83a147f53c1efba286cf039543a5c908ad1d
4
+ data.tar.gz: 0a87f6e082c435ca7f20851b3ec16faa71ce0ba8
5
5
  SHA512:
6
- metadata.gz: 758328e28fe67df58ad60e9dba0f4a5ad8741795eab435c5c0dac31495f59f1861898f1a25836176f6522ace603ebb8a0da25b0c01bc39c15befa18f4f00f333
7
- data.tar.gz: 197f52f761d88ec095145a1dd337a1ece4397cb8fc413fed1b33ec1692d6813861605d6bba43a636c80991cc4d2222ac43b84211a7dd7ff4036f9ef11237c706
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 finder_key.blank?
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 << method_name
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
@@ -4,9 +4,6 @@ module Journey::Resource::Embed
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- # def self.search(q)
8
- # instantiate_collection format.decode(post(:search, q: q).body)
9
- # end
10
7
  end
11
8
 
12
9
  end
@@ -2,7 +2,7 @@ module Journey
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 8
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
8
  end
@@ -101,30 +101,30 @@ describe Journey::Resource do
101
101
  end
102
102
 
103
103
  describe '::Embed' do
104
- class Client < Journey::Resource
104
+ class Asset < Journey::Resource
105
105
  end
106
106
 
107
- class Technician < Journey::Resource
107
+ class Fault < Journey::Resource
108
108
  end
109
109
 
110
- class Asset < Journey::Resource
111
- belongs_to :client, embed: true
112
- belongs_to :technician, embed: true
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
- client = Client.create name: 'branch'
117
- technician = Technician.create name: 'technician'
116
+ asset = Asset.create name: 'asset'
117
+ fault = Fault.create name: 'fault'
118
118
 
119
- asset = Asset.create name: 'asset', client_id: client.id, technician_id: technician.id
120
- id = asset.id
121
- asset = Asset.find(id)
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(asset.attributes['client']).to eq client
124
- expect(asset.client).to eq client
123
+ expect(job.attributes['asset']).to eq asset
124
+ expect(job.asset).to eq asset
125
125
 
126
- expect(asset.attributes['technician']).to eq technician
127
- expect(asset.technician).to eq technician
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.7
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-14 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr