input_source 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
File without changes
data/lib/input_source.rb CHANGED
@@ -2,9 +2,19 @@ require "input_source/version"
2
2
 
3
3
  module InputSource
4
4
  def self.load!
5
- require 'input_source/engine'
6
- require 'input_source/railtie'
7
- end
5
+ require 'input_source/engine'
6
+ require 'input_source/railtie'
7
+
8
+ warn <<-EOW
9
+
10
+ DEPRECATION WARNING: Gem 'input_source' has been moved into 'active_tools' gem.
11
+ Further development of 'input_source' will no longer continue.
12
+
13
+ Thank you!
14
+
15
+ EOW
16
+
17
+ end
8
18
  end
9
19
 
10
20
  InputSource.load!
@@ -1,14 +1,14 @@
1
1
  module InputSource
2
- module Dispatch
3
- module ControllerExtension
4
- def converse(hash, key)
5
- converse_parameters(hash[key], key)
6
- end
2
+ module Dispatch
3
+ module ControllerExtension
4
+ def converse(hash, key)
5
+ converse_parameters(hash[key], key)
6
+ end
7
7
 
8
- private
8
+ private
9
9
 
10
- include ConverseParameters
11
- end
12
- end
13
-
10
+ include ConverseParameters
11
+ end
12
+ end
13
+
14
14
  end
@@ -1,41 +1,41 @@
1
1
  module InputSource
2
- module Dispatch
3
- module ConverseParameters
4
- # Converse parameters
2
+ module Dispatch
3
+ module ConverseParameters
4
+ # Converse parameters
5
5
 
6
- def converse_parameters(value, prefix = nil, parent = nil)
7
- case value
8
- when Hash
9
- value.each do |k, v|
10
- new_prefix = prefix ? "#{prefix}[#{k}]" : k
11
- converse_parameters(v, new_prefix, value)
12
- end
13
- when Array
14
- value.each do |e|
15
- new_prefix = "#{prefix}[]"
16
- converse_parameters(e, new_prefix, value)
17
- end
18
- else
19
- value
20
- end
21
- value.tap do |v|
22
- v.singleton_class.send(:undef_method, :belongs_to) if v.respond_to?(:belongs_to)
23
- v.define_singleton_method :belongs_to do
24
- parent
25
- end
26
- v.singleton_class.send(:undef_method, :input_source) if v.respond_to?(:input_source)
27
- v.define_singleton_method :input_source do
28
- prefix.to_s
29
- end
30
- end
31
- end
32
-
33
- # private
34
- #
35
- # def normalize_parameters(value)
36
- # converse_parameters(super)
37
- # end
6
+ def converse_parameters(value, prefix = nil, parent = nil)
7
+ case value
8
+ when Hash
9
+ value.each do |k, v|
10
+ new_prefix = prefix ? "#{prefix}[#{k}]" : k
11
+ converse_parameters(v, new_prefix, value)
12
+ end
13
+ when Array
14
+ value.each do |e|
15
+ new_prefix = "#{prefix}[]"
16
+ converse_parameters(e, new_prefix, value)
17
+ end
18
+ else
19
+ value
20
+ end
21
+ value.tap do |v|
22
+ v.singleton_class.send(:undef_method, :belongs_to) if v.respond_to?(:belongs_to)
23
+ v.define_singleton_method :belongs_to do
24
+ parent
25
+ end
26
+ v.singleton_class.send(:undef_method, :input_source) if v.respond_to?(:input_source)
27
+ v.define_singleton_method :input_source do
28
+ prefix.to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ # private
34
+ #
35
+ # def normalize_parameters(value)
36
+ # converse_parameters(super)
37
+ # end
38
38
 
39
- end
40
- end
39
+ end
40
+ end
41
41
  end
@@ -1,13 +1,13 @@
1
1
  module InputSource
2
- module Dispatch
3
- module RequestExtension
4
- include ConverseParameters
5
-
6
- private
2
+ module Dispatch
3
+ module RequestExtension
4
+ include ConverseParameters
5
+
6
+ private
7
7
 
8
- def normalize_parameters(value)
9
- converse_parameters(super)
10
- end
11
- end
12
- end
8
+ def normalize_parameters(value)
9
+ converse_parameters(super)
10
+ end
11
+ end
12
+ end
13
13
  end
@@ -1,33 +1,33 @@
1
1
  require 'input_source/models/errors_extension'
2
2
 
3
3
  module InputSource
4
- ActiveModel::Errors.send(:include, ErrorsExtension)
4
+ ActiveModel::Errors.send(:include, ErrorsExtension)
5
5
 
6
- module ActiveRecordExtension
6
+ module ActiveRecordExtension
7
7
  extend ActiveSupport::Concern
8
-
8
+
9
9
  module ClassMethods
10
10
  end
11
11
 
12
- def assign_attributes(*args)
13
- new_attributes = args.first
14
- if new_attributes.respond_to?(:input_source)
15
- @input_source = new_attributes.input_source
16
- end
17
- super(*args)
18
- end
12
+ def assign_attributes(*args)
13
+ new_attributes = args.first
14
+ if new_attributes.respond_to?(:input_source)
15
+ @input_source = new_attributes.input_source
16
+ end
17
+ super(*args)
18
+ end
19
19
 
20
- def field_of(attribute)
21
- if @input_source && has_attribute?(attribute)
22
- "#{@input_source}[#{attribute}]".tap do |input_source|
23
- input_source.instance_eval do
24
- def to_id
25
- self.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
26
- end
27
- end
28
- end
29
- end
30
- end
31
-
20
+ def field_of(attribute)
21
+ if @input_source && has_attribute?(attribute)
22
+ "#{@input_source}[#{attribute}]".tap do |input_source|
23
+ input_source.instance_eval do
24
+ def to_id
25
+ self.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
32
  end
33
33
  end
@@ -1,19 +1,19 @@
1
1
  module InputSource
2
- module ErrorsExtension
3
- extend ActiveSupport::Concern
2
+ module ErrorsExtension
3
+ extend ActiveSupport::Concern
4
4
 
5
- included do
6
- delegate :field_of, :to => :@base
7
- end
5
+ included do
6
+ delegate :field_of, :to => :@base
7
+ end
8
8
 
9
- def fields
10
- keys.map {|attribute| field_of(attribute)}.compact.tap do |names|
11
- names.instance_eval do
12
- def ids
13
- self.map(&:to_id)
14
- end
15
- end
16
- end
17
- end
18
- end
9
+ def fields
10
+ keys.map {|attribute| field_of(attribute)}.compact.tap do |names|
11
+ names.instance_eval do
12
+ def ids
13
+ self.map(&:to_id)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
19
  end
@@ -6,16 +6,16 @@ module InputSource
6
6
  ActiveSupport.on_load :active_record do
7
7
  require 'input_source/models/active_record_extension'
8
8
 
9
- # For Rails > 3.2.9: ActiveRecord::AttributeAssignment
10
- # For Rails < 3.2.9: ActiveRecord::Base
11
- include ActiveRecordExtension
9
+ # For Rails > 3.2.9: ActiveRecord::AttributeAssignment
10
+ # For Rails < 3.2.9: ActiveRecord::Base
11
+ include ActiveRecordExtension
12
12
  end
13
13
  ActiveSupport.on_load :action_controller do
14
- require 'input_source/dispatch/converse_parameters'
14
+ require 'input_source/dispatch/converse_parameters'
15
15
  require 'input_source/dispatch/request_extension'
16
- require 'input_source/dispatch/controller_extension'
17
- ActionDispatch::Request.send(:include, Dispatch::RequestExtension)
18
- include Dispatch::ControllerExtension
16
+ require 'input_source/dispatch/controller_extension'
17
+ ActionDispatch::Request.send(:include, Dispatch::RequestExtension)
18
+ include Dispatch::ControllerExtension
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module InputSource
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: input_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Model's attrubutes remembers the field name
15
15
  email:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
- rubygems_version: 1.8.24
58
+ rubygems_version: 1.8.25
59
59
  signing_key:
60
60
  specification_version: 3
61
61
  summary: Attribute knows the field name. Helpful to improvise with errors handling