volt 0.4.15 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/volt/cli.rb +3 -1
- data/lib/volt/models/array_model.rb +12 -0
- data/lib/volt/models/model.rb +12 -0
- data/lib/volt/models/model_helpers.rb +11 -0
- data/spec/models/model_spec.rb +17 -0
- data/templates/project/Gemfile.tt +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a2b43155cd2eff6d57093ba3b4b15997a5cfdd3
|
4
|
+
data.tar.gz: dadd732fcb8340fe213d056448ee6d5352a1d272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83b59d9de4351e1ca97a037c5be7c7f9909345e3e219430da05fb87919a75912e38f4d24354ac4b63f45b0532d2e3f73040f20db8a9e182b699a4ce0511469bc
|
7
|
+
data.tar.gz: 2c8ec7ffb3d62321648c1bae3ec55908683c208b620f57a341d4263bb40f0abb2fecb8c8f0a3f9388b423effa4a859953399e1cda04ac832d01e665b8e121190
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.17
|
data/lib/volt/cli.rb
CHANGED
@@ -6,7 +6,9 @@ class CLI < Thor
|
|
6
6
|
|
7
7
|
desc "new PROJECT_NAME", "generates a new project."
|
8
8
|
def new(name)
|
9
|
-
|
9
|
+
# Grab the current volt version
|
10
|
+
version = File.read(File.join(File.dirname(__FILE__), '../../VERSION'))
|
11
|
+
directory("project", name, {:version => version})
|
10
12
|
|
11
13
|
say "Bundling Gems...."
|
12
14
|
`cd #{name} ; bundle -j 4`
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'volt/models/model_wrapper'
|
2
|
+
require 'volt/models/model_helpers'
|
2
3
|
|
3
4
|
class ArrayModel < ReactiveArray
|
4
5
|
include ModelWrapper
|
6
|
+
include ModelHelpers
|
5
7
|
|
6
8
|
attr_reader :parent, :path, :persistor, :options
|
7
9
|
|
@@ -51,6 +53,16 @@ class ArrayModel < ReactiveArray
|
|
51
53
|
ArrayModel.new(*args)
|
52
54
|
end
|
53
55
|
|
56
|
+
# Convert the model to an array all of the way down
|
57
|
+
def to_a
|
58
|
+
array = []
|
59
|
+
attributes.each do |value|
|
60
|
+
array << deep_unwrap(value)
|
61
|
+
end
|
62
|
+
|
63
|
+
return array
|
64
|
+
end
|
65
|
+
|
54
66
|
private
|
55
67
|
# Takes the persistor if there is one and
|
56
68
|
def setup_persistor(persistor)
|
data/lib/volt/models/model.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'volt/models/model_wrapper'
|
2
2
|
require 'volt/models/array_model'
|
3
|
+
require 'volt/models/model_helpers'
|
3
4
|
require 'volt/reactive/object_tracking'
|
4
5
|
|
5
6
|
class NilMethodCall < NoMethodError
|
@@ -16,6 +17,7 @@ class Model
|
|
16
17
|
include ReactiveTags
|
17
18
|
include ModelWrapper
|
18
19
|
include ObjectTracking
|
20
|
+
include ModelHelpers
|
19
21
|
|
20
22
|
attr_accessor :attributes
|
21
23
|
attr_reader :parent, :path, :persistor, :options
|
@@ -228,6 +230,16 @@ class Model
|
|
228
230
|
raise "Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion"
|
229
231
|
end
|
230
232
|
|
233
|
+
# Convert the model to a hash all of the way down.
|
234
|
+
def to_h
|
235
|
+
hash = {}
|
236
|
+
attributes.each_pair do |key, value|
|
237
|
+
hash[key] = deep_unwrap(value)
|
238
|
+
end
|
239
|
+
|
240
|
+
return hash
|
241
|
+
end
|
242
|
+
|
231
243
|
|
232
244
|
private
|
233
245
|
# Clear the previous value and assign a new one
|
data/spec/models/model_spec.rb
CHANGED
@@ -438,6 +438,23 @@ describe Model do
|
|
438
438
|
expect(a.index(a[1])).to eq(1)
|
439
439
|
end
|
440
440
|
|
441
|
+
it "should convert to a hash, and unwrap all of the way down" do
|
442
|
+
a = Model.new
|
443
|
+
a._items << {_name: 'Test1', _other: {_time: 'Now'}}
|
444
|
+
a._items << {_name: 'Test2', _other: {_time: 'Later'}}
|
445
|
+
|
446
|
+
item1 = a._items[0].to_h.cur
|
447
|
+
expect(item1[:_name]).to eq('Test1')
|
448
|
+
expect(item1[:_other][:_time]).to eq('Now')
|
449
|
+
|
450
|
+
all_items = a._items.to_a.cur
|
451
|
+
|
452
|
+
expect(all_items).to eq([
|
453
|
+
{:_name=>"Test1", :_other=>{:_time=>"Now"}},
|
454
|
+
{:_name=>"Test2", :_other=>{:_time=>"Later"}}
|
455
|
+
])
|
456
|
+
end
|
457
|
+
|
441
458
|
|
442
459
|
describe "model paths" do
|
443
460
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
@@ -353,6 +353,7 @@ files:
|
|
353
353
|
- lib/volt/models.rb
|
354
354
|
- lib/volt/models/array_model.rb
|
355
355
|
- lib/volt/models/model.rb
|
356
|
+
- lib/volt/models/model_helpers.rb
|
356
357
|
- lib/volt/models/model_wrapper.rb
|
357
358
|
- lib/volt/models/persistors/array_store.rb
|
358
359
|
- lib/volt/models/persistors/base.rb
|