bzsnippets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snippets.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexander Kostrov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Snippets
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'snippets'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install snippets
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/snippets.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "snippets/version"
2
+ require "snippets/object/env_attribute"
3
+ require "snippets/mime_tempfile"
4
+ module Snippets
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'tempfile'
2
+ module Snippets
3
+ class MimeTempfile < Tempfile
4
+ def content_type
5
+ mime = `file --mime -br #{self.path}`.strip
6
+ mime = mime.gsub(/^.*: */,"")
7
+ mime = mime.gsub(/;.*$/,"")
8
+ mime = mime.gsub(/,.*$/,"")
9
+ mime
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,61 @@
1
+ require 'active_support/concern'
2
+ require 'bzproxies'
3
+ module Snippets
4
+ module Object
5
+ module EnvAttribute
6
+ extend ActiveSupport::Concern
7
+
8
+ class EnvironmentProxy < Proxy
9
+
10
+ def __getobj__
11
+ env = @options[:env].call
12
+ @target[env]
13
+ end
14
+
15
+ def all_envs
16
+ @target
17
+ end
18
+ end
19
+
20
+ def fetch_source src
21
+ YAML.load_file(src)
22
+ end
23
+
24
+ module ClassMethods
25
+ def env_attribute *args
26
+ if (args.last.kind_of?(::Hash) && (args.length > 1))
27
+ opts = args.pop
28
+ end
29
+ opts ||= {}
30
+ raise "setup :source option" unless opts[:source]
31
+ if defined? Rails
32
+ opts[:env] ||= lambda{ Rails.env }
33
+ else
34
+ opts[:env] ||= lambda do
35
+ if defined? Rails
36
+ Rails.env
37
+ else
38
+ ENV["RAILS_ENV"] || "development"
39
+ end
40
+ end
41
+ end
42
+ proxy_accessor *args, :proxy => EnvironmentProxy, :source => opts[:source], :env => opts[:env]
43
+ args.each do |i|
44
+ old = "_#{i}".to_sym
45
+ alias_method old, i
46
+ define_method i do
47
+ value = self.send(old)
48
+ unless value
49
+ self.send("#{i}=", fetch_source(opts[:source]))
50
+ self.send(old)
51
+ else
52
+ value
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Snippets
2
+ VERSION = "0.0.1"
3
+ end
data/snippets.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/snippets/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexander Kostrov"]
6
+ gem.email = ["akostrov@spbtv.com"]
7
+ gem.description = "Ruby and Rails code snippets"
8
+ gem.summary = "Snippets"
9
+ gem.homepage = "http://spbtv.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bzsnippets"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Snippets::VERSION
17
+ gem.add_dependency "activesupport", "~> 3"
18
+ gem.add_dependency "bzproxies", "~> 0.1.7"
19
+ end
@@ -0,0 +1,35 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ staging:
22
+ adapter: mysql2
23
+ database: mainadmin
24
+ username: mainadmin
25
+ password: jatsyewg9
26
+ host: staging.elt.spbtv.com
27
+ encoding: utf8
28
+ pool: 5
29
+
30
+ production:
31
+ adapter: mysql2
32
+ database: mainadmin
33
+ username: root
34
+ host: localhost
35
+ encoding: utf8
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+ require 'pathname'
4
+
5
+ describe Snippets::Object do
6
+ before(:all) do
7
+ class Tester
8
+ include Snippets::Object::EnvAttribute
9
+ env_attribute :a, :source => (Pathname.new(__FILE__) + '../../fixtures/config.yml'), :env => lambda{"test"}
10
+ env_attribute :a1, :source => (Pathname.new(__FILE__) + '../../fixtures/config.yml'), :env => lambda{"development"}
11
+ end
12
+ end
13
+ it "should work" do
14
+ i = Tester.new
15
+ (i.a == YAML.load_file(Pathname.new(__FILE__) + '../../fixtures/config.yml')["test"]).should be_true
16
+ end
17
+
18
+ it "given env function should work" do
19
+ i = Tester.new
20
+ (Tester.new.a1 == YAML.load_file(Pathname.new(__FILE__) + '../../fixtures/config.yml')["development"]).should be_true
21
+ end
22
+
23
+ it "should return config without envs with all_envs" do
24
+ i = Tester.new
25
+ Tester.new.a1.all_envs.should == YAML.load_file(Pathname.new(__FILE__) + '../../fixtures/config.yml')
26
+ end
27
+
28
+ it "should correctly allow change params" do
29
+ a = Tester.new
30
+ a.a1 = YAML.load_file(Pathname.new(__FILE__) + '../../fixtures/config.yml')
31
+ a.a1["adapter"] = "dfsdfdsfdsf"
32
+ a.a1.target["development"]["adapter"].should == "dfsdfdsfdsf"
33
+ end
34
+
35
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require_relative '../lib/snippets'
data/unicorn ADDED
@@ -0,0 +1,52 @@
1
+ #! /bin/sh
2
+
3
+ # File: /etc/init.d/unicorn
4
+
5
+ ### BEGIN INIT INFO
6
+ # Provides: unicorn
7
+ # Required-Start: $local_fs $remote_fs $network $syslog
8
+ # Required-Stop: $local_fs $remote_fs $network $syslog
9
+ # Default-Start: 2 3 4 5
10
+ # Default-Stop: 0 1 6
11
+ # Short-Description: starts the unicorn web server
12
+ # Description: starts unicorn
13
+ ### END INIT INFO
14
+
15
+ DAEMON="/home/deploy/.rvm/bin/bootup_unicorn_rails"
16
+ DAEMON_OPTS="-c /home/deploy/apps/intranet/production/current/config/unicorn/production.rb -E production -D"
17
+ NAME=unicorn
18
+ DESC="Unicorn app for intranet"
19
+ PID=/home/deploy/apps/intranet/production/shared/pids/unicorn.pid
20
+
21
+
22
+ case "$1" in
23
+ start)
24
+ echo -n "Starting $DESC: "
25
+ su - deploy -c "$DAEMON $DAEMON_OPTS"
26
+ echo "$NAME."
27
+ ;;
28
+ stop)
29
+ echo -n "Stopping $DESC: "
30
+ kill -QUIT `cat $PID`
31
+ echo "$NAME."
32
+ ;;
33
+ restart)
34
+ echo -n "Restarting $DESC: "
35
+ kill -QUIT `cat $PID`
36
+ sleep 1
37
+ su - deploy -c "$DAEMON $DAEMON_OPTS"
38
+ echo "$NAME."
39
+ ;;
40
+ reload)
41
+ echo -n "Reloading $DESC configuration: "
42
+ kill -HUP `cat $PID`
43
+ echo "$NAME."
44
+ ;;
45
+ *)
46
+ echo "Usage: $NAME {start|stop|restart|reload}" >&2
47
+ exit 1
48
+ ;;
49
+ esac
50
+
51
+ exit 0
52
+
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bzsnippets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexander Kostrov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bzproxies
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.7
46
+ description: Ruby and Rails code snippets
47
+ email:
48
+ - akostrov@spbtv.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/snippets.rb
60
+ - lib/snippets/mime_tempfile.rb
61
+ - lib/snippets/object/env_attribute.rb
62
+ - lib/snippets/version.rb
63
+ - snippets.gemspec
64
+ - spec/fixtures/config.yml
65
+ - spec/object/env_attribute_spec.rb
66
+ - spec/spec_helper.rb
67
+ - unicorn
68
+ homepage: http://spbtv.com
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.21
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Snippets
92
+ test_files:
93
+ - spec/fixtures/config.yml
94
+ - spec/object/env_attribute_spec.rb
95
+ - spec/spec_helper.rb
96
+ has_rdoc: