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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1b1635ef6a0d61f2fd334870249bffd6a032a55
4
- data.tar.gz: 761fe764d63b32d5ce1e65b482b4094d4a4f12fa
3
+ metadata.gz: 1a2b43155cd2eff6d57093ba3b4b15997a5cfdd3
4
+ data.tar.gz: dadd732fcb8340fe213d056448ee6d5352a1d272
5
5
  SHA512:
6
- metadata.gz: a8c3e07939e8f5f22104bb0e16f30fa4dfb5270741341d31239aa0d4c746089134545a6cfc4214da7915fd6581d191113a8c0560bfee5f3b10c225242a9db17f
7
- data.tar.gz: 6fcd81d3d469133e8552869c03a86ca1be4902608e5f825ce580c98716e5a4e8d72be35afafb0aad99097195abf16f6a73e49f03fa94bc08190a91d3377a8696
6
+ metadata.gz: 83b59d9de4351e1ca97a037c5be7c7f9909345e3e219430da05fb87919a75912e38f4d24354ac4b63f45b0532d2e3f73040f20db8a9e182b699a4ce0511469bc
7
+ data.tar.gz: 2c8ec7ffb3d62321648c1bae3ec55908683c208b620f57a341d4263bb40f0abb2fecb8c8f0a3f9388b423effa4a859953399e1cda04ac832d01e665b8e121190
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.15
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
- directory("project", name)
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)
@@ -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
@@ -0,0 +1,11 @@
1
+ module ModelHelpers
2
+ def deep_unwrap(value)
3
+ if value.is_a?(Model)
4
+ value = value.to_h
5
+ elsif value.is_a?(ArrayModel)
6
+ value = value.to_a
7
+ end
8
+
9
+ return value
10
+ end
11
+ end
@@ -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
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'volt'
3
+ gem 'volt', '<%= config[:version] %>'
4
4
 
5
5
  # Twitter bootstrap
6
6
  gem 'volt-bootstrap'
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.15
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