whales_actions 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 729d14e7c36e47baa7b6ece335aa8855df26100a
4
- data.tar.gz: 76b3bdfb42daa6e6bdf9bdc73f3c84462d1e0529
3
+ metadata.gz: d4f1a9a93db81f15a84a14a25821077d696a96b5
4
+ data.tar.gz: 8df87e596aed8593a70f9d25a16d80e539b9f93c
5
5
  SHA512:
6
- metadata.gz: ba5c27610cecae1f4c44845af782b13fdfbc836b7560b3c5faedaff0d5549aee36d4f928c533d17c61193e351e9383864a3061d0cb968621e4db05f36c228532
7
- data.tar.gz: 6fae79cb8f83a022596053bac703e027e761e1a8adee893e1be1c024c8890eb80e54b88a2c13443729130b264c7d4f6a2d171f1587e6dd1d01f689a7520a36a7
6
+ metadata.gz: d8b2d94420fb72107228c08a0c89a4c62aa6beb5cc8f7f158798712b331a460da0a73a24f2016978f900cd169a1416265a75e8707f5b368008356c8b69c68d66
7
+ data.tar.gz: f97af9c79477326a1891188d3df84c848877a10d164c11d6dca84e7380c170551aa3d843a0bc88bda996a0095f03799f747803883247d2b0ccfc887637a7fd01
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "webrick"
6
- gem "activesupport"
data/Gemfile.lock CHANGED
@@ -1,12 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whales_actions (0.1.0)
4
+ whales_actions (0.1.1)
5
+ activesupport
6
+ json (= 1.8.3)
7
+ webrick
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
8
11
  specs:
9
- activesupport (4.2.4)
12
+ activesupport (4.2.5)
10
13
  i18n (~> 0.7)
11
14
  json (~> 1.7, >= 1.7.7)
12
15
  minitest (~> 5.1)
@@ -75,14 +78,12 @@ PLATFORMS
75
78
  ruby
76
79
 
77
80
  DEPENDENCIES
78
- activesupport
79
81
  bundler (~> 1.10)
80
82
  guard
81
83
  guard-rspec
82
84
  pry
83
85
  rake (~> 10.0)
84
86
  rspec
85
- webrick
86
87
  whales_actions!
87
88
 
88
89
  BUNDLED WITH
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rspec/core/rake_task"
4
4
  # Default directory to look in is `/specs`
5
5
  # Run with `rake spec`
6
6
  RSpec::Core::RakeTask.new(:spec) do |task|
7
- task.rspec_opts = ['--color', '--format', 'nested']
7
+ task.rspec_opts = ['--color']
8
8
  end
9
9
 
10
10
  task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module WhalesActions
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -10,7 +10,7 @@ require_relative '../whales_dispatch/session'
10
10
 
11
11
  module WhalesController
12
12
  class Base
13
- attr_reader :params
13
+ attr_reader :params
14
14
  attr_accessor :res, :req
15
15
 
16
16
  def initialize(request, response, route_params = {})
@@ -46,7 +46,7 @@ module WhalesController
46
46
  self.res.body = content
47
47
  @already_built_response = true
48
48
  session.store_session(res)
49
- flash.store_flash(res)
49
+ # flash.store_flash(res)
50
50
  end
51
51
 
52
52
  def redirect_to(url)
@@ -55,7 +55,7 @@ module WhalesController
55
55
  self.res.status = 302
56
56
  @already_built_response = true
57
57
  session.store_session(res)
58
- flash.store_flash(res)
58
+ # flash.store_flash(res)
59
59
  end
60
60
 
61
61
  def render(template_name, file_location = nil)
@@ -72,9 +72,9 @@ module WhalesController
72
72
  private
73
73
 
74
74
  def verify_authenticity_token
75
- unless params[:authenticity_token] == session["authenticity_token"]
76
- raise "Missing authenticity token"
77
- end
75
+ # unless params[:authenticity_token] == session["authenticity_token"]
76
+ # raise "Missing authenticity token"
77
+ # end
78
78
  end
79
79
 
80
80
  end
@@ -1,59 +1,59 @@
1
- class DefaultActions
2
- attr_reader :actions
3
- def initialize(resource)
4
- @resource = resource.to_s
5
- @resource_id = @resource.singularize + "_id"
6
- @actions = all
7
- end
8
-
9
- def parse_action_restrictions(restrictions_hash)
10
- raise(ArgumentError) if restrictions_hash.size > 1
11
- send(:only, restrictions_hash[:only]) if restrictions_hash[:only]
12
- send(:except, restrictions_hash[:except]) if restrictions_hash[:except]
13
- end
14
-
15
- def index
16
- { index: { suffix: "$", method: :get } }
17
- end
18
-
19
- def show
20
- { show: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :post } }
21
- end
22
-
23
- def new
24
- { new: { suffix: "/new$", method: :get } }
25
- end
26
-
27
- def create
28
- { create: { suffix: "$", method: :post } }
29
- end
30
-
31
- def edit
32
- { edit: { suffix: "/(?<#{@resource_id}>\\d+)/edit$", method: :get } }
33
- end
34
-
35
- def update
36
- { update: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :put } }
37
- end
38
-
39
- def destroy
40
- { destroy: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :delete } }
41
- end
42
-
43
- private
44
-
45
- def all
46
- DefaultActions.instance_methods(false).drop(2).reduce({}) do |accum, method|
47
- accum.merge(send(method))
48
- end
49
- end
50
-
51
- def only(action_names)
52
- @actions.keep_if { |key, _| action_names.include?(key) }
53
- end
54
-
55
- def except(action_names)
56
- @actions.keep_if { |key, _| !action_names.include?(key) }
57
- end
58
-
59
- end
1
+ # class DefaultActions
2
+ # attr_reader :actions
3
+ # def initialize(resource)
4
+ # @resource = resource.to_s
5
+ # @resource_id = @resource.singularize + "_id"
6
+ # @actions = all
7
+ # end
8
+ #
9
+ # def parse_action_restrictions(restrictions_hash)
10
+ # raise(ArgumentError) if restrictions_hash.size > 1
11
+ # send(:only, restrictions_hash[:only]) if restrictions_hash[:only]
12
+ # send(:except, restrictions_hash[:except]) if restrictions_hash[:except]
13
+ # end
14
+ #
15
+ # def index
16
+ # { index: { suffix: "$", method: :get } }
17
+ # end
18
+ #
19
+ # def show
20
+ # { show: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :post } }
21
+ # end
22
+ #
23
+ # def new
24
+ # { new: { suffix: "/new$", method: :get } }
25
+ # end
26
+ #
27
+ # def create
28
+ # { create: { suffix: "$", method: :post } }
29
+ # end
30
+ #
31
+ # def edit
32
+ # { edit: { suffix: "/(?<#{@resource_id}>\\d+)/edit$", method: :get } }
33
+ # end
34
+ #
35
+ # def update
36
+ # { update: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :put } }
37
+ # end
38
+ #
39
+ # def destroy
40
+ # { destroy: { suffix: "/(?<#{@resource_id}>\\d+)$", method: :delete } }
41
+ # end
42
+ #
43
+ # private
44
+ #
45
+ # def all
46
+ # DefaultActions.instance_methods(false).drop(2).reduce({}) do |accum, method|
47
+ # accum.merge(send(method))
48
+ # end
49
+ # end
50
+ #
51
+ # def only(action_names)
52
+ # @actions.keep_if { |key, _| action_names.include?(key) }
53
+ # end
54
+ #
55
+ # def except(action_names)
56
+ # @actions.keep_if { |key, _| !action_names.include?(key) }
57
+ # end
58
+ #
59
+ # end
@@ -6,7 +6,7 @@ module WhalesDispatch
6
6
 
7
7
  def initialize(request)
8
8
  request.cookies.each do |cookie|
9
- @value_for_now = JSON.parse(cookie.value) if cookie.name == '_rails_lite_flash'
9
+ @value_for_now = JSON.parse(cookie.value) if cookie.name == '_whales_flash'
10
10
  end
11
11
  @value_for_now ||= {}
12
12
  @value_for_next = {}
@@ -26,7 +26,7 @@ module WhalesDispatch
26
26
  end
27
27
 
28
28
  def store_flash(response)
29
- cookie = WEBrick::Cookie.new('_rails_lite_flash', @value_for_next.to_json)
29
+ cookie = WEBrick::Cookie.new('_whales_flash', @value_for_next.to_json)
30
30
  cookie.path = '/'
31
31
  response.cookies << cookie
32
32
  end
@@ -1,25 +1,25 @@
1
- class Resource
2
- attr_reader :pattern
3
-
4
- def initialize(noun, suffix, parent)
5
- @noun = noun.to_s
6
- @pattern = build_route_pattern(suffix, parent)
7
- end
8
-
9
- def build_route_pattern(suffix, parent)
10
- base = build_base(parent)
11
- Regexp.new(base + @noun + suffix)
12
- end
13
-
14
- def build_base(parent)
15
- if parent.empty?
16
- "^/"
17
- else
18
- "^/#{parent}/(?<#{parent.singularize}_id>\\d+)/"
19
- end
20
- end
21
-
22
- def classify
23
- klass = Object.const_get(@noun.capitalize + "Controller")
24
- end
25
- end
1
+ # class Resource
2
+ # attr_reader :pattern
3
+ #
4
+ # def initialize(noun, suffix, parent)
5
+ # @noun = noun.to_s
6
+ # @pattern = build_route_pattern(suffix, parent)
7
+ # end
8
+ #
9
+ # def build_route_pattern(suffix, parent)
10
+ # base = build_base(parent)
11
+ # Regexp.new(base + @noun + suffix)
12
+ # end
13
+ #
14
+ # def build_base(parent)
15
+ # if parent.empty?
16
+ # "^/"
17
+ # else
18
+ # "^/#{parent}/(?<#{parent.singularize}_id>\\d+)/"
19
+ # end
20
+ # end
21
+ #
22
+ # def classify
23
+ # klass = Object.const_get(@noun.capitalize + "Controller")
24
+ # end
25
+ # end
@@ -1,11 +1,12 @@
1
1
  module WhalesDispatch
2
2
  class Router
3
3
 
4
+ HTML_METHODS = [:get, :post, :patch, :put, :delete]
4
5
  attr_reader :routes
5
6
 
6
7
  def initialize
7
8
  @routes = []
8
- @last_parent_route = ""
9
+ # @last_parent_route = ""
9
10
  end
10
11
 
11
12
  def add_route(pattern, method, controller_class, action_name)
@@ -16,30 +17,30 @@ module WhalesDispatch
16
17
  instance_eval(&proc)
17
18
  end
18
19
 
19
- def resources(controller_noun, scope, **action_restrictions)
20
- @last_parent_route = "" if scope == :parent
21
- controller_actions = DefaultActions.new(controller_noun)
22
- controller_actions.parse_action_restrictions(action_restrictions)
23
- build_resources(controller_noun, controller_actions)
20
+ # def resources(controller_noun, scope, **action_restrictions)
21
+ # @last_parent_route = "" if scope == :parent
22
+ # controller_actions = DefaultActions.new(controller_noun)
23
+ # controller_actions.parse_action_restrictions(action_restrictions)
24
+ # build_resources(controller_noun, controller_actions)
25
+ #
26
+ # if block_given?
27
+ # @last_parent_route = controller_noun.to_s
28
+ # yield
29
+ # end
30
+ # end
31
+ #
32
+ # def build_resources(controller_noun, controller_actions)
33
+ # controller_actions.actions.each do |action_name, action_hash|
34
+ #
35
+ # resource = Resource.new(
36
+ # controller_noun, action_hash[:suffix], @last_parent_route
37
+ # )
38
+ #
39
+ # send action_hash[:method], resource.pattern, resource.classify, action_name
40
+ # end
41
+ # end
24
42
 
25
- if block_given?
26
- @last_parent_route = controller_noun.to_s
27
- yield
28
- end
29
- end
30
-
31
- def build_resources(controller_noun, controller_actions)
32
- controller_actions.actions.each do |action_name, action_hash|
33
-
34
- resource = Resource.new(
35
- controller_noun, action_hash[:suffix], @last_parent_route
36
- )
37
-
38
- send action_hash[:method], resource.pattern, resource.classify, action_name
39
- end
40
- end
41
-
42
- [:get, :post, :put, :delete].each do |http_method|
43
+ HTML_METHODS.each do |http_method|
43
44
  define_method(http_method) do |pattern, controller_class, action_name|
44
45
  add_route(pattern, http_method, controller_class, action_name)
45
46
  end
@@ -58,6 +59,6 @@ module WhalesDispatch
58
59
  res.body = "Could not find matching route."
59
60
  end
60
61
  end
61
-
62
+
62
63
  end
63
64
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'yaml'
2
2
  require 'webrick'
3
3
 
4
4
  module WhalesDispatch
@@ -6,7 +6,7 @@ module WhalesDispatch
6
6
 
7
7
  def initialize(request)
8
8
  request.cookies.each do |cookie|
9
- @value = JSON.parse(cookie.value) if cookie.name == '_rails_lite_app'
9
+ @value = YAML.load(cookie.value) if cookie.name == '_whales_app'
10
10
  end
11
11
  @value ||= {}
12
12
  end
@@ -20,9 +20,11 @@ module WhalesDispatch
20
20
  end
21
21
 
22
22
  def store_session(response)
23
- cookie = WEBrick::Cookie.new('_rails_lite_app', @value.to_json)
23
+ cookie = WEBrick::Cookie.new('_whales_app', @value.to_yaml)
24
+ puts "got past cookie"
24
25
  cookie.path = '/'
25
26
  response.cookies << cookie
27
+ puts "added cookie to response"
26
28
  end
27
29
 
28
30
  end
@@ -15,6 +15,9 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
+ spec.add_dependency "activesupport"
19
+ spec.add_dependency "webrick"
20
+
18
21
  spec.add_development_dependency "bundler", "~> 1.10"
19
22
  spec.add_development_dependency "rake", "~> 10.0"
20
23
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whales_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Horton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webrick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement