Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Top level actions:

* using RecursiveOpenStruct for parsed form values
* enables easier (non hash like) usage
  • Loading branch information...
commit d894104ace8022ca64d7909a9252109f6a841afe 1 parent a8adeaf
@elvanja authored
View
9 Gemfile
@@ -9,13 +9,4 @@ group :test do
gem 'activemodel'
gem 'activesupport'
gem 'rspec'
-
- ## Assets
- #gem 'rails-assets-sugar'
- #gem 'rails-assets-angular'
- #gem 'rails-assets-angular-ui'
- #
- ## Only for tests
- #gem 'rails-assets-angular-mocks'
- #gem 'rails-assets-angular-scenario'
end
View
4 Gemfile.lock
@@ -4,6 +4,7 @@ PATH
deckhand (0.1.0)
activesupport
haml
+ recursive-open-struct
sprockets-browserify
GEM
@@ -29,6 +30,7 @@ GEM
minitest (4.7.5)
multi_json (1.8.4)
rack (1.5.2)
+ recursive-open-struct (0.4.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
@@ -37,7 +39,7 @@ GEM
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
- sprockets (2.10.1)
+ sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
View
1  deckhand.gemspec
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport'
s.add_dependency 'sprockets-browserify'
s.add_dependency 'haml'
+ s.add_dependency 'recursive-open-struct'
end
View
5 lib/deckhand/form.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/class/attribute'
require 'active_model'
require 'backport/active_model/model'
+require 'recursive-open-struct'
class Deckhand::Form
extend ActiveModel::Callbacks
@@ -112,6 +113,9 @@ def resolve_value(value, options)
elsif type == Float
value.to_f
+ elsif options[:group]
+ RecursiveOpenStruct.new(value, recurse_over_arrays: true)
@elvanja Owner
elvanja added a note

This is the only iffy place.
It works for new page action, but I am not sure whether it should resolve over group members?

@levity Collaborator
levity added a note

Makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
elsif options[:multiple]
value.map do |subval|
resolved = subval.map do |k, v|
@@ -125,5 +129,4 @@ def resolve_value(value, options)
value
end
end
-
end
View
7 spec/lib/deckhand/form_spec.rb
@@ -37,7 +37,7 @@
context "with groups" do
it 'accepts regular inputs' do
form = ExampleForm.new(album: {title: 'Music for the Jilted Generation'})
- expect(form.album[:title]).to eq('Music for the Jilted Generation')
+ expect(form.album.title).to eq('Music for the Jilted Generation')
end
it 'embeds list values within group' do
@@ -56,9 +56,8 @@
{title: 'Poison'},
{title: 'No Good (Start The Dance)'}
]})
- expect(form.album[:songs].size).to eq(3)
- expect(form.album[:songs].last[:title]).to eq('No Good (Start The Dance)')
+ expect(form.album.songs.size).to eq(3)
+ expect(form.album.songs.last.title).to eq('No Good (Start The Dance)')
end
end
-
end

0 comments on commit d894104

Please sign in to comment.
Something went wrong with that request. Please try again.