resourcerer 0.2.2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +0,0 @@
1
- require 'resourcerer/strategies/assign_attributes'
2
-
3
- module Resourcerer
4
- module Strategies
5
- module AssignFromMethod
6
- include AssignAttributes
7
-
8
- def attributes
9
- super || attributes_from_method
10
- end
11
-
12
- private
13
-
14
- def attributes_from_method
15
- controller.send(attributes_method) if resource_params
16
- end
17
-
18
- def attributes_method
19
- config.attributes_method || "#{name}_params"
20
- end
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- require 'resourcerer/strategies/assign_attributes'
2
-
3
- module Resourcerer
4
- module Strategies
5
- module AssignFromParams
6
- include AssignAttributes
7
-
8
- def attributes
9
- super || resource_params
10
- end
11
- end
12
- end
13
- end
@@ -1,34 +0,0 @@
1
- require 'resourcerer/strategy'
2
- require 'active_support/core_ext/module/delegation'
3
-
4
- module Resourcerer
5
- module Strategies
6
- class DefaultStrategy < Strategy
7
- delegate :get?, :delete?, to: :request
8
-
9
- def resource
10
- if id
11
- find_resource(id)
12
- else
13
- build_resource
14
- end
15
- end
16
-
17
- def id
18
- @id ||= params[finder_param] || params[finder_attribute]
19
- end
20
-
21
- def finder_param
22
- config.finder_param || inflector.finder_param
23
- end
24
-
25
- def find_resource(id)
26
- config.finder.try(:call, id) || model.find_by(finder_attribute => id)
27
- end
28
-
29
- def build_resource
30
- config.builder.try(:call) || model.new
31
- end
32
- end
33
- end
34
- end
@@ -1,10 +0,0 @@
1
- require 'resourcerer/strategies/default_strategy'
2
- require 'resourcerer/strategies/assign_from_params'
3
-
4
- module Resourcerer
5
- module Strategies
6
- class EagerAttributesStrategy < DefaultStrategy
7
- include Strategies::AssignFromParams
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- require 'resourcerer/strategies/default_strategy'
2
- require 'resourcerer/strategies/assign_from_method'
3
-
4
- module Resourcerer
5
- module Strategies
6
- class StrongParametersStrategy < DefaultStrategy
7
- include Strategies::AssignFromMethod
8
- end
9
- end
10
- end
@@ -1,55 +0,0 @@
1
- require 'resourcerer/inflector'
2
- require 'resourcerer/resource_configuration'
3
-
4
- module Resourcerer
5
- class Strategy
6
- attr_reader :controller, :name, :options, :config_proc
7
- attr_writer :model, :inflector
8
-
9
- def initialize(controller, name, options={}, config_proc=nil)
10
- @controller, @name, @options, @config_proc = controller, name.to_s, options, config_proc
11
- end
12
-
13
- def resource
14
- raise 'Implement in subclass'
15
- end
16
-
17
- protected
18
-
19
- # Subclasses may provide an extended version of ResourceConfiguration to extend the DSL
20
- def build_configuration(options)
21
- ResourceConfiguration.new(options)
22
- end
23
-
24
- def config
25
- @config ||= build_configuration(options).tap do |rc|
26
- rc.instance_eval(&config_proc) if config_proc # This evaluates the configuration in the DSL block
27
- end
28
- end
29
-
30
- def inflector
31
- @inflector ||= Resourcerer::Inflector.new(name, model, finder_attribute)
32
- end
33
-
34
- def model
35
- @model ||= case config.model
36
- when Class, Module
37
- config.model
38
- else
39
- Resourcerer::Inflector.class_for(config.model || name)
40
- end
41
- end
42
-
43
- def finder_attribute
44
- config.find_by || :id
45
- end
46
-
47
- def params
48
- controller.params
49
- end
50
-
51
- def request
52
- controller.request
53
- end
54
- end
55
- end