ccs-provider 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/ccs_provider.rb +46 -0
  2. metadata +46 -0
@@ -0,0 +1,46 @@
1
+ module Provider
2
+ def provide(params)
3
+ provide_action(params, false, false)
4
+ end
5
+
6
+ def provide!(params)
7
+ provide_action(params, true, false)
8
+ end
9
+
10
+ def provide_value!(params)
11
+ provide_action(params,true,true)
12
+ end
13
+
14
+ def provide_value(params)
15
+ provide_action(params,false,true)
16
+ end
17
+
18
+ private
19
+
20
+ def provide_action(params,raise_exception,only_value)
21
+ only_value = only_value
22
+ attrs = (params.is_a? Array) ? params : params.to_a
23
+ r = only_value ? [] : {}
24
+ attrs.each do |attr|
25
+ begin
26
+ value = eval("self.#{ attr.gsub('/', '.') }")
27
+ if only_value
28
+ value.to_s
29
+ r.push(value)
30
+ else
31
+ r.update(attr => value )
32
+ end
33
+ rescue NoMethodError
34
+ error_msg = "\033[31m [can't provide] #{self.class.name}#ID='#{id}' can't provide '#{attr}' \033[0m"
35
+ if raise_exception
36
+ raise(error_msg)
37
+ else
38
+ only_value ? r.push(" ") : r.update(attr => nil)
39
+ end
40
+ end
41
+ end
42
+ r
43
+ end
44
+ end
45
+
46
+ ActiveRecord::Base.send(:include, Provider)
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ccs-provider
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ccs_provider.rb
21
+ homepage:
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.25
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: provider is ths first version
45
+ test_files: []
46
+ has_rdoc: