Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Gemmification #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replace manual setting primitives with active supports configurable
  • Loading branch information
shellandbull committed May 21, 2016
commit 838c92cf742af64b929a8610228d95945e7336b3
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global

settings.yml.erb
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ruby "2.2.3"
gem "rack"
gem "redis"
gem "colorize"
gem "activesupport"

group :test, :development do
gem "rspec"
Expand Down
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (4.1.15)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
coderay (1.1.1)
colorize (0.7.7)
diff-lcs (1.2.5)
Expand All @@ -20,11 +26,14 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
i18n (0.7.0)
json (1.8.3)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
lumberjack (1.0.10)
method_source (0.8.2)
minitest (5.8.4)
mock_redis (0.16.1)
nenv (0.3.0)
notiffany (0.0.8)
Expand Down Expand Up @@ -57,11 +66,15 @@ GEM
shellany (0.0.1)
slop (3.6.0)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activesupport
colorize
guard-rspec
mock_redis
Expand Down
2 changes: 1 addition & 1 deletion lib/popsicle.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rack"

require "active_support/configurable"
module Popsicle
end
30 changes: 22 additions & 8 deletions lib/popsicle/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

module Popsicle
class Application
attr_accessor :request, :store, :app_name, :headers, :index_key

def initialize(store:, app_name:, headers:, index_key:)
@store = store
@app_name = app_name
@headers = headers
@index_key = index_key
end
include ActiveSupport::Configurable
attr_accessor :request
config_accessor :store
config_accessor :app_name
config_accessor :headers
config_accessor :index_key

def call(env)
@request = Rack::Request.new(env)
Expand All @@ -25,6 +23,22 @@ def found_revision
store.get(revision_key).to_s
end

def store
@_config[:store]
end

def app_name
@_config[:app_name]
end

def headers
@_config[:headers]
end

def index_key
@_config[:index_key]
end

def revision_requested?
request.params.key?(index_key)
end
Expand Down
23 changes: 0 additions & 23 deletions lib/popsicle/settings.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/popsicle/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Popsicle
VERSION = "0.1.4"
VERSION = "0.2.0"
end
13 changes: 0 additions & 13 deletions settings.sample.yml.erb

This file was deleted.

10 changes: 6 additions & 4 deletions spec/acceptance/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
end

def app
@app ||= Popsicle::Application.new(store: app_settings[:store],
app_name: app_settings[:app_name],
headers: app_settings[:headers],
index_key: app_settings[:index_key])
@app ||= Popsicle::Application.new.tap do |instance|
instance.store = app_settings[:store]
instance.app_name = app_settings[:app_name]
instance.headers = app_settings[:headers]
instance.index_key = app_settings[:index_key]
end
end

describe "Making a request to the server" do
Expand Down
23 changes: 17 additions & 6 deletions spec/popsicle/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@
let(:index_key) { double(:index_key) }

subject do
described_class.new(store: store,
app_name: app_name,
headers: headers,
index_key: index_key)
described_class.new.tap do |instance|
instance.store = store
instance.app_name = app_name
instance.headers = headers
instance.index_key = index_key
end
end

describe "#initialize" do
it "assigns store, app_name, headers, index_key" do
describe "attributes" do
it "store" do
expect(subject.store).to eq(store)
end

it "app_name" do
expect(subject.app_name).to eq(app_name)
end

it "headers" do
expect(subject.headers).to eq(headers)
end

it "index_key" do
expect(subject.index_key).to eq(index_key)
end
end
Expand Down
40 changes: 0 additions & 40 deletions spec/popsicle/settings_spec.rb

This file was deleted.