Skip to content

Commit

Permalink
🍺 Create ElasticsearchReader::Config and add Readme files
Browse files Browse the repository at this point in the history
 - Add Guard-bundler gem and configure it
 - Add ActiveSupport gem
 - Fix RuboCop issues
 - Create `ElasticsearchReader::Config` Class as a Singleton
 - Add specs for `ElasticsearchReader::Config` Class
 - Delegate all methods from `ElasticsearchReader::Config` to `ElasticsearchReader`
 - Add PULL_REQUEST_TEMPLATE.md
 - Add ISSUE_TEMPLATE.md
 - Add CONTRIBUTING.md
 - Add .ruby-version
  • Loading branch information
adham90 committed Jun 16, 2017
1 parent 7e5a438 commit 54ab797
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
engines:
fixme:
enabled: true
exclude_fingerprints:
- 303f76d18a54a13422463f2edab9bacd
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.4.1
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing to ElasticsearchReader

### Style (Ruby)

We use Rubocop to enforce a few style-related conventions. Run the command rubocop to check for any style violations before submitting pull requests.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in elasticsearch_reader.gemspec
gemspec

gem 'activesupport'

gem 'guard'
gem 'guard-bundler', require: false
gem 'guard-rspec'

gem 'redcarpet'
Expand Down
14 changes: 14 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)
Expand All @@ -16,3 +18,15 @@ guard :rspec, cmd: 'bundle exec rspec' do
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
end

guard :bundler do
require 'guard/bundler'
require 'guard/bundler/verify'
helper = Guard::Bundler::Verify.new

files = ['Gemfile']
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }

# Assume files are symlinked from somewhere
files.each { |file| watch(helper.real_path(file)) }
end
32 changes: 32 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Step 1: Are you in the right place?

* For issues or feature requests related to the code **in this repository** file a Github issue.
* For general technical questions, post a question on [StackOverflow](http://stackoverflow.com/) tagged appropriately.

### Step 2: Describe your environment

* Gem version: _____
* Rails version: _____
* Ruby version: _____

### Step 3: Describe the problem:

#### Steps to reproduce:

1. _____
2. _____
3. _____

#### Observed Results:

* What happened? This could be a description, log output, etc.

#### Expected Results:

* What did you expect to happen?

#### Relevant Code:

```
// TODO(you): code here to reproduce the problem
```
5 changes: 5 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Todos
- [ ] Tests
- [ ] RuboCop
- [ ] Documentation
- [ ] Changelog
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## TODO

- [ ] Configrations and settings
- [x] [Configrations and settings](https://github.com/adham90/elasticsearch_reader/pull/1)
- [ ] Object mapper
- [ ] Relations
- [ ] Query DSL
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'elasticsearch_reader'
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_reader.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '0.48.1'
spec.add_development_dependency 'rspec-its'
spec.add_development_dependency 'rubocop', '0.48.1'
spec.add_development_dependency 'rspec-collection_matchers'
spec.add_development_dependency 'appraisal'

Expand Down
25 changes: 25 additions & 0 deletions lib/elasticsearch_reader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# frozen_string_literal: true

require 'active_support/concern'
require 'active_support/deprecation'
require 'active_support/json'
require 'active_support/log_subscriber'

require 'active_support/core_ext/array/access'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/hash/reverse_merge'
require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/numeric/bytes'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/inclusion'
require 'active_support/core_ext/string/inflections'

require 'singleton'
require 'elasticsearch_reader/version'
require 'elasticsearch_reader/config'

module ElasticsearchReader
# Your code goes here...
class << self
def config
ElasticsearchReader::Config.instance
end
delegate(*ElasticsearchReader::Config.delegated, to: :config)
end
end
54 changes: 54 additions & 0 deletions lib/elasticsearch_reader/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

module ElasticsearchReader
# ElasticsearchReader core configuration.
class Config
include Singleton

attr_accessor :settings, :logger,

# Where ElasticsearchReader expects to find index definitions
# within a Rails app folder.
:indices_path

def self.delegated
public_instance_methods -
superclass.public_instance_methods -
Singleton.public_instance_methods
end

def initialize
@settings = {}
@indices_path = 'app/indices'
end

# ElasticsearchReader configurations. There is two ways to set it up:
# use `ElasticsearchReader.settings=` method or, create
# `config/elasticsearch_reader.yml` file (ERB supported), this file
# support All Elasticsearch::Client options supports.
#
# test:
# host: 'localhost:9250'
#
def configuration
yaml_settings.merge(settings.deep_symbolize_keys).tap do |configuration|
configuration[:logger] = logger
configuration[:indices_path] ||= indices_path
end
end

private

def yaml_settings
@yaml_settings ||= begin
file = File.join(Dir.pwd, 'config', 'elasticsearch_reader.yml')

if File.exist?(file)
yaml = ERB.new(File.read(file)).result
hash = YAML.safe_load(yaml)
hash&.try(:deep_symbolize_keys)
end
end || {}
end
end
end
4 changes: 3 additions & 1 deletion lib/elasticsearch_reader/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ElasticsearchReader
VERSION = '0.1.0'.freeze
VERSION = '0.1.0'
end
18 changes: 18 additions & 0 deletions spec/elasticsearch_reader/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'spec_helper'

describe ElasticsearchReader::Config do
subject { described_class.send(:new) }

its(:logger) { should be_nil }
its(:indices_path) { should == 'app/indices' }

describe '#configuration' do
before { subject.settings = { indices_path: 'app/foobar' } }

specify do
expect(subject.configuration).to include(indices_path: 'app/foobar')
end
end
end
2 changes: 2 additions & 0 deletions spec/elasticsearch_reader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ElasticsearchReader do
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'elasticsearch_reader'
require 'rspec/its'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 54ab797

Please sign in to comment.