decent_exposure 2.3.3 → 3.0.0.beta1

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.
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "support/rails_app"
3
+ require "rspec/rails"
4
+
5
+ describe BirdsController, type: :controller do
6
+ context "finds bird by id" do
7
+ let(:mockingbird){ double("Bird") }
8
+ before{ expect(Bird).to receive(:find).with("mockingbird").once.and_return(mockingbird) }
9
+ after{ expect(controller.bird).to eq(mockingbird) }
10
+
11
+ it "finds model by id" do
12
+ get :show, params: { id: "mockingbird" }
13
+ end
14
+
15
+ it "finds model by bird_id" do
16
+ get :show, params: { bird_id: "mockingbird" }
17
+ end
18
+ end
19
+
20
+ it "builds bird if id is not provided" do
21
+ bird = double("Bird")
22
+ expect(Bird).to receive(:new).and_return(bird)
23
+ get :show
24
+ expect(controller.bird).to eq(bird)
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require "decent_exposure"
@@ -0,0 +1,37 @@
1
+ require "active_support/all"
2
+ require "action_controller"
3
+ require "action_dispatch"
4
+ require "rails"
5
+
6
+ module Rails
7
+ class App
8
+ def env_config; {} end
9
+
10
+ def routes
11
+ @routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
12
+ routes.draw do
13
+ resource :birds
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.application
20
+ @app ||= App.new
21
+ end
22
+ end
23
+
24
+ class Bird
25
+ end
26
+
27
+ class ApplicationController < ActionController::Base
28
+ include Rails.application.routes.url_helpers
29
+ end
30
+
31
+ class BirdsController < ApplicationController
32
+ expose :bird
33
+
34
+ def show
35
+ head :ok
36
+ end
37
+ end
metadata CHANGED
@@ -1,123 +1,145 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decent_exposure
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.3
4
+ version: 3.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
+ - Pavel Pravosud
7
8
  - Stephen Caudill
8
- - Jon Larkowski
9
- - Joshua Davey
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2016-01-08 00:00:00.000000000 Z
12
+ date: 2016-05-08 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- name: rspec
15
+ name: railties
17
16
  requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
18
  - - "~>"
20
19
  - !ruby/object:Gem::Version
21
- version: '3'
22
- type: :development
20
+ version: 5.x
21
+ type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - "~>"
27
26
  - !ruby/object:Gem::Version
28
- version: '3'
27
+ version: 5.x
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 5.x
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 5.x
29
42
  - !ruby/object:Gem::Dependency
30
43
  name: rspec-rails
31
44
  requirement: !ruby/object:Gem::Requirement
32
45
  requirements:
33
46
  - - "~>"
34
47
  - !ruby/object:Gem::Version
35
- version: '3'
48
+ version: '3.0'
36
49
  type: :development
37
50
  prerelease: false
38
51
  version_requirements: !ruby/object:Gem::Requirement
39
52
  requirements:
40
53
  - - "~>"
41
54
  - !ruby/object:Gem::Version
42
- version: '3'
55
+ version: '3.0'
43
56
  - !ruby/object:Gem::Dependency
44
- name: actionpack
57
+ name: rake
45
58
  requirement: !ruby/object:Gem::Requirement
46
59
  requirements:
47
- - - ">="
60
+ - - "~>"
48
61
  - !ruby/object:Gem::Version
49
- version: 3.1.0
62
+ version: '10.3'
50
63
  type: :development
51
64
  prerelease: false
52
65
  version_requirements: !ruby/object:Gem::Requirement
53
66
  requirements:
54
- - - ">="
67
+ - - "~>"
55
68
  - !ruby/object:Gem::Version
56
- version: 3.1.0
69
+ version: '10.3'
57
70
  - !ruby/object:Gem::Dependency
58
- name: activesupport
71
+ name: pry
59
72
  requirement: !ruby/object:Gem::Requirement
60
73
  requirements:
61
74
  - - ">="
62
75
  - !ruby/object:Gem::Version
63
- version: 3.1.0
76
+ version: '0'
64
77
  type: :development
65
78
  prerelease: false
66
79
  version_requirements: !ruby/object:Gem::Requirement
67
80
  requirements:
68
81
  - - ">="
69
82
  - !ruby/object:Gem::Version
70
- version: 3.1.0
83
+ version: '0'
71
84
  description: "\n DecentExposure helps you program to an interface, rather than
72
85
  an\n implementation in your Rails controllers. The fact of the matter is that\n
73
86
  \ sharing state via instance variables in controllers promotes close coupling\n
74
87
  \ with views. DecentExposure gives you a declarative manner of exposing an\n
75
88
  \ interface to the state that controllers contain and thereby decreasing\n coupling
76
89
  and improving your testability and overall design.\n "
77
- email: scaudill@gmail.com
90
+ email:
91
+ - info@hashrocket.com
78
92
  executables: []
79
93
  extensions: []
80
94
  extra_rdoc_files: []
81
95
  files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
82
100
  - README.md
101
+ - Rakefile
102
+ - decent_exposure.gemspec
103
+ - decent_exposure.png
104
+ - hashrocket_logo.png
83
105
  - lib/decent_exposure.rb
84
- - lib/decent_exposure/active_record_strategy.rb
85
- - lib/decent_exposure/active_record_with_eager_attributes_strategy.rb
86
- - lib/decent_exposure/configuration.rb
87
- - lib/decent_exposure/constant_resolver.rb
88
- - lib/decent_exposure/error.rb
89
- - lib/decent_exposure/expose.rb
106
+ - lib/decent_exposure/attribute.rb
107
+ - lib/decent_exposure/behavior.rb
108
+ - lib/decent_exposure/context.rb
109
+ - lib/decent_exposure/controller.rb
90
110
  - lib/decent_exposure/exposure.rb
91
- - lib/decent_exposure/inflector.rb
92
- - lib/decent_exposure/strategies/assign_from_method.rb
93
- - lib/decent_exposure/strategies/assign_from_params.rb
94
- - lib/decent_exposure/strategizer.rb
95
- - lib/decent_exposure/strategy.rb
96
- - lib/decent_exposure/strong_parameters_strategy.rb
111
+ - lib/decent_exposure/flow.rb
97
112
  - lib/decent_exposure/version.rb
98
- homepage: http://github.com/voxdolo/decent_exposure
113
+ - spec/controller_spec.rb
114
+ - spec/integration_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/rails_app.rb
117
+ homepage: https://github.com/hashrocket/decent_exposure
99
118
  licenses:
100
- - WTFPL
119
+ - MIT
101
120
  metadata: {}
102
121
  post_install_message:
103
- rdoc_options:
104
- - "--charset=UTF-8"
122
+ rdoc_options: []
105
123
  require_paths:
106
124
  - lib
107
125
  required_ruby_version: !ruby/object:Gem::Requirement
108
126
  requirements:
109
- - - ">="
127
+ - - "~>"
110
128
  - !ruby/object:Gem::Version
111
- version: '0'
129
+ version: '2.0'
112
130
  required_rubygems_version: !ruby/object:Gem::Requirement
113
131
  requirements:
114
- - - ">="
132
+ - - ">"
115
133
  - !ruby/object:Gem::Version
116
- version: 1.3.6
134
+ version: 1.3.1
117
135
  requirements: []
118
136
  rubyforge_project:
119
- rubygems_version: 2.4.3
137
+ rubygems_version: 2.5.1
120
138
  signing_key:
121
139
  specification_version: 4
122
140
  summary: A helper for creating declarative interfaces in controllers
123
- test_files: []
141
+ test_files:
142
+ - spec/controller_spec.rb
143
+ - spec/integration_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/support/rails_app.rb
@@ -1,84 +0,0 @@
1
- require 'decent_exposure/strategy'
2
- require 'active_support/core_ext/module/delegation'
3
-
4
- module DecentExposure
5
- class ActiveRecordStrategy < Strategy
6
- delegate :plural?, :parameter, :to => :inflector
7
- delegate :get?, :delete?, :post?, :put?, :patch?, :to => :request
8
-
9
- def singular?
10
- !plural?
11
- end
12
-
13
- def collection
14
- inflector.plural.to_sym
15
- end
16
-
17
- def scope
18
- @scope ||= if options[:ancestor]
19
- ancestor_scope
20
- else
21
- default_scope
22
- end
23
- end
24
-
25
- def ancestor_scope
26
- if plural?
27
- controller.send(options[:ancestor]).send(inflector.plural)
28
- else
29
- controller.send(options[:ancestor])
30
- end
31
- end
32
-
33
- def default_scope
34
- if controller.respond_to?(collection) && !plural?
35
- controller.send(collection)
36
- else
37
- model
38
- end
39
- end
40
-
41
- def finder
42
- options[:finder] || :find
43
- end
44
-
45
- def collection_resource
46
- return scope if scope.respond_to?(:proxy_association) || scope.respond_to?(:each)
47
- scope.send(scope_method)
48
- end
49
-
50
- def id
51
- if finder_parameter = options[:finder_parameter]
52
- params[finder_parameter]
53
- else
54
- params[parameter] || params[:id]
55
- end
56
- end
57
-
58
- def singular_resource
59
- if id
60
- scope.send(finder, id)
61
- else
62
- scope.new
63
- end
64
- end
65
-
66
- def resource
67
- if plural?
68
- collection_resource
69
- else
70
- singular_resource
71
- end
72
- end
73
-
74
- private
75
-
76
- def scope_method
77
- if defined?(ActiveRecord) && ActiveRecord::VERSION::MAJOR > 3
78
- :all
79
- else
80
- :scoped
81
- end
82
- end
83
- end
84
- end
@@ -1,8 +0,0 @@
1
- require 'decent_exposure/active_record_strategy'
2
- require 'decent_exposure/strategies/assign_from_params'
3
-
4
- module DecentExposure
5
- class ActiveRecordWithEagerAttributesStrategy < ActiveRecordStrategy
6
- include Strategies::AssignFromParams
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- module DecentExposure
2
- class Configuration
3
- def initialize(&block)
4
- instance_exec(&block) if block_given?
5
- end
6
-
7
- def merge(other)
8
- options.merge(other)
9
- end
10
-
11
- def options
12
- @options ||= {}
13
- end
14
-
15
- def method_missing(key,value)
16
- self.options[key] = value
17
- end
18
- end
19
- end
@@ -1,34 +0,0 @@
1
- require 'active_support/inflector'
2
- require 'active_support/core_ext/string'
3
-
4
- module DecentExposure
5
- class ConstantResolver
6
- attr_reader :context, :constant_name
7
- def initialize(constant_name, context=Object)
8
- @context, @constant_name = context, constant_name.classify
9
- end
10
-
11
- def constant
12
- immediate_child || namespace_qualified
13
- end
14
-
15
- private
16
-
17
- def immediate_child
18
- context.constants.map do |c|
19
- context.const_get(c) if c.to_s == constant_name
20
- end.compact.first
21
- end
22
-
23
- def namespace_qualified
24
- namespace.const_get(constant_name)
25
- end
26
-
27
- def namespace
28
- path = context.to_s
29
- name = path[0...(path.rindex('::') || 0)]
30
- return Object if name.blank?
31
- name.constantize
32
- end
33
- end
34
- end
@@ -1,4 +0,0 @@
1
- module DecentExposure
2
- # Public: A generic Error class for decent_exposure
3
- class Error < ::StandardError; end
4
- end
@@ -1,62 +0,0 @@
1
- require 'decent_exposure/strategizer'
2
- require 'decent_exposure/configuration'
3
-
4
- module DecentExposure
5
- module Expose
6
- def self.extended(base)
7
- base.class_eval do
8
- class_attribute :_decent_configurations
9
- self._decent_configurations ||= Hash.new(Configuration.new)
10
-
11
- def _resources
12
- @_resources ||= {}
13
- end
14
-
15
- protected_instance_variables << "@_resources"
16
- end
17
- end
18
-
19
- def _exposures
20
- @_exposures ||= {}
21
- end
22
-
23
- def decent_configuration(name=:default,&block)
24
- self._decent_configurations = _decent_configurations.merge(name => Configuration.new(&block))
25
- end
26
-
27
- def expose!(*args, &block)
28
- set_callback(:process_action, :before, args.first)
29
- expose(*args, &block)
30
- end
31
-
32
- def expose(name, options={}, &block)
33
- if ActionController::Base.instance_methods.include?(name.to_sym)
34
- Kernel.warn "[WARNING] You are exposing the `#{name}` method, " \
35
- "which overrides an existing ActionController method of the same name. " \
36
- "Consider a different exposure name\n" \
37
- "#{caller.first}"
38
- end
39
-
40
- config = options[:config] || :default
41
- options = _decent_configurations[config].merge(options)
42
-
43
- _exposures[name] = exposure = Strategizer.new(name, options, &block).strategy
44
-
45
- define_exposure_methods(name, exposure)
46
- end
47
-
48
- private
49
-
50
- def define_exposure_methods(name, exposure)
51
- define_method(name) do
52
- return _resources[name] if _resources.has_key?(name)
53
- _resources[name] = exposure.call(self)
54
- end
55
- helper_method name
56
-
57
- define_method("#{name}=") do |value|
58
- _resources[name] = value
59
- end
60
- end
61
- end
62
- end