angular_sprinkles 0.2.0 → 0.2.1

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: 5b64d257dda0cf1e8a99f220b37cd4038d4cf8cf
4
- data.tar.gz: 4a6c9bc4529978427aff6c3b4ba8e14b997bd7fd
3
+ metadata.gz: 63255ac5499bbd7a2c8e7445bbd83abde35e2b9c
4
+ data.tar.gz: c094e71015dfec90b47ff9a84bad5002b6cb19b4
5
5
  SHA512:
6
- metadata.gz: d198024dbbfba69d739051c5df36717df41a62eab9792b794da9dfcdad20b35557e2fcf809ec9d4832c3c44b361a43e789cd56d4fc65cdcbf83483abd557e264
7
- data.tar.gz: 2159d526dde0559420cf6144e025b1fbaa5b2a057156153d11dafa507d833bc21ce030a76d9d26dc40900550e3ab3027b791c1c773906e6dbd6e7013882d00a4
6
+ metadata.gz: 9c037097cb261fbac5ba6cc2c566a986ceaa03374fd3ab39a66771c26409ac98923662dfd84889e7e95ed01e8523e522ab3ff7c65457881632e032c1ad0bdcc1
7
+ data.tar.gz: 83a3d681ac5ec8b42059e25be8f58e543827a46b8bfce601152af50912f357e11a187584a661f069771d847627434e1da05941e4fe80b66182bddef8af8fb5e8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: angular_sprinkles 0.2.0 ruby lib
5
+ # stub: angular_sprinkles 0.2.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "angular_sprinkles"
9
- s.version = "0.2.0"
9
+ s.version = "0.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
40
40
  "lib/angular_sprinkles/directive/input.rb",
41
41
  "lib/angular_sprinkles/directive/name.rb",
42
42
  "lib/angular_sprinkles/engine.rb",
43
- "lib/angular_sprinkles/form_binder.rb",
44
43
  "lib/angular_sprinkles/form_binder/base.rb",
45
44
  "lib/angular_sprinkles/form_binder/check_box.rb",
46
45
  "lib/angular_sprinkles/form_binder/default.rb",
@@ -65,6 +64,9 @@ Gem::Specification.new do |s|
65
64
  "spec/angular_sprinkles/directive/html_spec.rb",
66
65
  "spec/angular_sprinkles/directive/input_spec.rb",
67
66
  "spec/angular_sprinkles/directive/name_spec.rb",
67
+ "spec/angular_sprinkles/form_binder/base_spec.rb",
68
+ "spec/angular_sprinkles/form_binder/check_box_spec.rb",
69
+ "spec/angular_sprinkles/form_binder/default_spec.rb",
68
70
  "spec/angular_sprinkles/key_generator_spec.rb",
69
71
  "spec/angular_sprinkles/model_decorator_spec.rb",
70
72
  "spec/angular_sprinkles/object_key_wrapper_spec.rb",
@@ -13,14 +13,16 @@ module AngularSprinkles
13
13
 
14
14
  def call
15
15
  # Let the original form helper raise the exception
16
- return @args if helper_is_going_raise_argument_error?
16
+ if helper_is_going_raise_argument_error?
17
+ return @args
18
+ end
17
19
 
18
- args_with_binding
20
+ augment_args
19
21
  end
20
22
 
21
23
  private
22
24
 
23
- def args_with_binding; raise NotImplementedError; end
25
+ def augment_args; raise NotImplementedError; end
24
26
 
25
27
  def helper_is_going_raise_argument_error?
26
28
  @args.count < required_parameters.count
@@ -3,15 +3,9 @@ module AngularSprinkles
3
3
  class CheckBox < Base
4
4
  private
5
5
 
6
- def args_with_binding
7
- binding = { 'ng-model' => @attribute_binding }
8
-
6
+ def augment_args
9
7
  @args.tap do |args|
10
- if args.many?
11
- args.second.reverse_merge!(binding)
12
- else
13
- args.push(binding)
14
- end
8
+ args.second.reverse_merge!({ "ng-model" => @attribute_binding })
15
9
  end
16
10
  end
17
11
  end
@@ -3,13 +3,13 @@ module AngularSprinkles
3
3
  class Default < Base
4
4
  private
5
5
 
6
- def args_with_binding
7
- binding = { 'ng-model' => @attribute_binding }
6
+ def augment_args
7
+ binding = { "ng-model" => @attribute_binding }
8
8
 
9
9
  @args.tap do |args|
10
10
  # Assume that optional params default to {}
11
11
  # This is a safe assumption for all helpers except check_box
12
- (@method.arity.abs - args.count).times { args.push({}) }
12
+ (@method.parameters.count - args.count).times { args.push({}) }
13
13
 
14
14
  # The last argument is always the one where ng-model should be appended
15
15
  args.last.reverse_merge!(binding)
@@ -1,6 +1,6 @@
1
1
  module AngularSprinkles
2
2
  module Mixins
3
- DEFAULT_HELPERS = ActionView::Helpers::FormBuilder.field_helpers - [:label, :fields_for]
3
+ DEFAULT_HELPERS = ActionView::Helpers::FormBuilder.field_helpers - [:label, :fields_for, :check_box]
4
4
  # DATE_HELPERS = [:date_select, :time_select, :datetime_select]
5
5
  # SELECT_HELPERS = [:select, :collection_select, :grouped_collection_select, :time_zone_select, :collection_check_boxes, :collection_radio_buttons]
6
6
  # ALL_HELPERS = [*DATE_HELPERS, *SELECT_HELPERS, *DEFAULT_HELPERS]
@@ -9,12 +9,18 @@ module AngularSprinkles
9
9
  DEFAULT_HELPERS.each do |helper|
10
10
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
11
11
  def bind_#{helper}(*args, &block)
12
- params = { helper: :#{helper}, method: method(:#{helper}), args: args, object: @object }
13
- args_with_binding = AngularSprinkles::FormBinder.new(params).call
12
+ params = { method: method(:#{helper}), args: args, object: @object }
13
+ args_with_binding = AngularSprinkles::FormBinder::Default.new(params).call
14
14
  #{helper}(*args_with_binding, &block)
15
15
  end
16
16
  RUBY_EVAL
17
17
  end
18
+
19
+ def bind_check_box(*args, &block)
20
+ params = { method: method(:check_box), args: args, object: @object }
21
+ args_with_binding = AngularSprinkles::FormBinder::CheckBox.new(params).call
22
+ check_box(*args_with_binding, &block)
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -9,7 +9,6 @@ require "angular_sprinkles/directive/html"
9
9
  require "angular_sprinkles/context"
10
10
  require "angular_sprinkles/counter"
11
11
  require "angular_sprinkles/engine"
12
- require "angular_sprinkles/form_binder"
13
12
  require "angular_sprinkles/form_binder/base"
14
13
  require "angular_sprinkles/form_binder/check_box"
15
14
  require "angular_sprinkles/form_binder/default"
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe AngularSprinkles::FormBinder::Base do
4
+ let(:method) { ->(name, value, *opts) {} }
5
+ let(:args) { [:attribute, {}] }
6
+ let(:attribute_binding) { double }
7
+ let(:object) { double(bind: attribute_binding) }
8
+ let(:params) { { method: method, args: args, object: object } }
9
+
10
+ subject { described_class.new(params) }
11
+
12
+ it 'raises NotImplementedError for augment_args' do
13
+ expect { subject.call }.to raise_error(NotImplementedError)
14
+ end
15
+
16
+ context "when not enough arguments are given" do
17
+ let(:args) { [:attribute] }
18
+
19
+ it "returns the args so that the original method will raise an exception" do
20
+ expect(subject.call).to eq(args)
21
+ end
22
+ end
23
+
24
+ context "when augment_args is implemented by a subclass" do
25
+ let!(:duped_args) { args.dup }
26
+
27
+ before do
28
+ subject.define_singleton_method(:augment_args, -> {})
29
+ end
30
+
31
+ it 'does not modify the original params' do
32
+ augmented_args = subject.call
33
+
34
+ expect(args).to eq(duped_args)
35
+ expect(args).not_to eq(augmented_args)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe AngularSprinkles::FormBinder::CheckBox do
4
+ let(:method) { ->(name, value, *opts) {} }
5
+ let(:args) { [:attribute, {}] }
6
+ let(:attribute_binding) { double }
7
+ let(:object) { double(bind: attribute_binding) }
8
+ let(:params) { { method: method, args: args, object: object } }
9
+
10
+ it 'returns the arguments with the second one augmented' do
11
+ augmented_args = described_class.new(params).call
12
+ expect(augmented_args.second["ng-model"]).to eq(attribute_binding)
13
+
14
+ args.push(1)
15
+ augmented_args = described_class.new(params).call
16
+ expect(augmented_args.second["ng-model"]).to eq(attribute_binding)
17
+
18
+ args.push(1, 0)
19
+ augmented_args = described_class.new(params).call
20
+ expect(augmented_args.second["ng-model"]).to eq(attribute_binding)
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe AngularSprinkles::FormBinder::Default do
4
+ let(:method) { ->(arg1, arg2, arg3 = {}, arg4 = {}, arg5 = {}) {} }
5
+ let(:args) { [:attribute, :something_else] }
6
+ let(:attribute_binding) { double }
7
+ let(:object) { double(bind: attribute_binding) }
8
+ let(:params) { { method: method, args: args, object: object } }
9
+
10
+ it 'returns the arguments with the second one augmented' do
11
+ augmented_args = described_class.new(params).call
12
+
13
+ expect(augmented_args[0]).to eq(:attribute)
14
+ expect(augmented_args[1]).to eq(:something_else)
15
+ expect(augmented_args[2]).to eq({})
16
+ expect(augmented_args[3]).to eq({})
17
+ expect(augmented_args[4]).to eq({ "ng-model" => attribute_binding })
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular_sprinkles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Scholz
@@ -87,7 +87,6 @@ files:
87
87
  - lib/angular_sprinkles/directive/input.rb
88
88
  - lib/angular_sprinkles/directive/name.rb
89
89
  - lib/angular_sprinkles/engine.rb
90
- - lib/angular_sprinkles/form_binder.rb
91
90
  - lib/angular_sprinkles/form_binder/base.rb
92
91
  - lib/angular_sprinkles/form_binder/check_box.rb
93
92
  - lib/angular_sprinkles/form_binder/default.rb
@@ -112,6 +111,9 @@ files:
112
111
  - spec/angular_sprinkles/directive/html_spec.rb
113
112
  - spec/angular_sprinkles/directive/input_spec.rb
114
113
  - spec/angular_sprinkles/directive/name_spec.rb
114
+ - spec/angular_sprinkles/form_binder/base_spec.rb
115
+ - spec/angular_sprinkles/form_binder/check_box_spec.rb
116
+ - spec/angular_sprinkles/form_binder/default_spec.rb
115
117
  - spec/angular_sprinkles/key_generator_spec.rb
116
118
  - spec/angular_sprinkles/model_decorator_spec.rb
117
119
  - spec/angular_sprinkles/object_key_wrapper_spec.rb
@@ -1,14 +0,0 @@
1
- module AngularSprinkles
2
- class FormBinder
3
- def self.new(args)
4
- helper = args.fetch(:helper)
5
-
6
- case helper
7
- when :check_box
8
- CheckBox.new(args)
9
- else
10
- Default.new(args)
11
- end
12
- end
13
- end
14
- end