geminus 0.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11e0cd7aefcbcafdd3fccf332b8728e35b86aaa1
4
+ data.tar.gz: 868ee7b7cb326a97a9d870967e2641469b1be5eb
5
+ SHA512:
6
+ metadata.gz: 55e5b8ce3553e47d373a101978042a49b8299ab41109053aa7887a56f4043b5714278887c9143f3acc98e980d44a0c641f0ab451c4ae401a1a221bb221373840
7
+ data.tar.gz: c5882a55477fc8c02fe6bbf1e16ae75c24542fb5be6e9e7532c1d9d47ad3acbaa97288eb2edeb29a191a709d30181876ccc2f76ff17bfa38bc168a76a36ccb4f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --backtrace
2
+ --color
3
+ --format=documentation
4
+ --order random
5
+ --require spec_helper
@@ -0,0 +1,72 @@
1
+ ## Styles ######################################################################
2
+
3
+ Style/AlignParameters:
4
+ EnforcedStyle: with_fixed_indentation
5
+
6
+ Style/BracesAroundHashParameters:
7
+ Enabled: false
8
+
9
+ # Broken (2014-12-15). Use `yardstick` gem instead.
10
+ # See: https://github.com/bbatsov/rubocop/issues/947
11
+ # TODO: Enable back once cop is fixed.
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Style/EmptyLineBetweenDefs:
16
+ AllowAdjacentOneLineDefs: true
17
+
18
+ Style/Encoding:
19
+ EnforcedStyle: when_needed
20
+
21
+ Style/HashSyntax:
22
+ EnforcedStyle: hash_rockets
23
+
24
+ Style/IndentHash:
25
+ EnforcedStyle: consistent
26
+
27
+ # New lambda syntax is as ugly to me as new syntax of Hash.
28
+ Style/Lambda:
29
+ Enabled: false
30
+
31
+ Style/MultilineOperationIndentation:
32
+ EnforcedStyle: indented
33
+
34
+ # IMHO `%r{foo/bar}` looks way more cleaner than `/foo\/bar/`.
35
+ # Enabling this cop also makes Guardfile (which is full of pathname regexps)
36
+ # look absolutley (style) inconsistent and terrible. Thus it should be on
37
+ # developer's choice whenever to user `%r` or not. Just like we don't enforce
38
+ # to use `["foo"]` over `%w(foo)` and so on.
39
+ Style/RegexpLiteral:
40
+ Enabled: false
41
+
42
+ # A bit useless restriction, that makes impossible aligning code like this:
43
+ #
44
+ # redis do |conn|
45
+ # conn.hset :k1, now
46
+ # conn.hincrby :k2, 123
47
+ # end
48
+ Style/SingleSpaceBeforeFirstArg:
49
+ Enabled: false
50
+
51
+ Style/StringLiterals:
52
+ EnforcedStyle: double_quotes
53
+
54
+ # Not all trivial readers/writers can be defined with attr_* methods
55
+ #
56
+ # class Example < SimpleDelegator
57
+ # def __getobj__
58
+ # @obj
59
+ # end
60
+ #
61
+ # def __setobj__(obj)
62
+ # @obj = obj
63
+ # end
64
+ # end
65
+ Style/TrivialAccessors:
66
+ Enabled: false
67
+
68
+ ## Metrics #####################################################################
69
+
70
+ Metrics/MethodLength:
71
+ CountComments: false
72
+ Max: 15
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+
7
+ before_install:
8
+ - gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "pry"
5
+ end
6
+
7
+ # Specify your gem's dependencies in geminus.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 SensorTower Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # Geminus
2
+
3
+ Simple way to share constants between backend/frontend.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem "geminus"
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install geminus
19
+
20
+ Inside of your Ruby program do:
21
+
22
+ require "geminus"
23
+
24
+ ...to pull it in as a dependency.
25
+
26
+
27
+ ## Usage
28
+
29
+ Extend module with Geminus and define some properties:
30
+
31
+ ``` ruby
32
+ require "geminus"
33
+
34
+ module Distribution
35
+ extend Geminus
36
+
37
+ prop :gentoo do
38
+ prop :name, "Gentoo".freeze
39
+ prop :homepage, "https://www.gentoo.org/".freeze
40
+ end
41
+
42
+ prop :debian do
43
+ prop :name, "Debian".freeze
44
+ prop :homepage, "https://www.debian.org/".freeze
45
+ end
46
+ end
47
+ ```
48
+
49
+ Now you can use them inside your application on backend:
50
+
51
+ ``` ruby
52
+ Distribution.gentoo.name # => "Gentoo"
53
+ ```
54
+
55
+ Then you can create dynamically generated JavaScript:
56
+
57
+ ``` ruby
58
+ // file: geminus.js.erb
59
+ <%= Geminus.generate_js %>
60
+ ```
61
+
62
+ Sourcing that dynamically generated JS file on your frontend will provide you
63
+ now with `Distribution` module:
64
+
65
+ ``` javascript
66
+ window.Distribution.gentoo.name // => "Gentoo"
67
+ ```
68
+
69
+
70
+ ## Contributing to Geminus
71
+
72
+ * Fork http.rb on GitHub
73
+ * Make your changes
74
+ * Ensure all tests pass (`bundle exec rake`)
75
+ * Send a pull request
76
+ * If we like them we'll merge them
77
+ * If we've accepted a patch, feel free to ask for commit access!
78
+
79
+
80
+ ## Copyright
81
+
82
+ Copyright (c) 2015 SensorTower Inc.
83
+ See LICENSE.txt for further details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "geminus/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "geminus"
10
+ spec.version = Geminus::VERSION
11
+ spec.authors = ["Alexey V Zapparov"]
12
+ spec.email = ["ixti@member.fsf.org"]
13
+
14
+ spec.summary = "Simply share constants between backend/frontend."
15
+ spec.description = "Simply share constants between backend/frontend."
16
+ spec.homepage = "https://github.com/sensortower/geminus"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "rubocop"
30
+ end
@@ -0,0 +1,31 @@
1
+ require "json"
2
+
3
+ require "geminus/version"
4
+ require "geminus/dsl"
5
+ require "geminus/container"
6
+ require "geminus/registry"
7
+
8
+ module Geminus
9
+ PREAMBLE = File.read("#{__dir__}/geminus/preamble.js").freeze
10
+
11
+ class << self
12
+ def extended(base)
13
+ Registry.instance << base
14
+
15
+ base.instance_variable_set(:@geminus, {})
16
+ base.send(:extend, DSL)
17
+ end
18
+
19
+ def generate_js
20
+ parts = [PREAMBLE]
21
+
22
+ Registry.instance.each do |geminus|
23
+ data = geminus.name.split("::".freeze).reverse
24
+ .inject(geminus.generate_js) { |a, e| "{#{JSON.dump e}:#{a}}" }
25
+ parts << "geminus(#{data});"
26
+ end
27
+
28
+ "(function(world){\n#{parts.join "\n;\n".freeze}\n}(this));"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ module Geminus
2
+ class Container
3
+ include DSL
4
+
5
+ def initialize(&blk)
6
+ @geminus = {}
7
+ instance_eval(&blk)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ module Geminus
2
+ module DSL
3
+ def prop(key, val = nil, &blk)
4
+ key = key.to_s
5
+
6
+ if blk
7
+ fail ArgumentError, "Pass either value or block" if val
8
+ val = Container.new(&blk)
9
+ end
10
+
11
+ @geminus[key] = val
12
+
13
+ instance_eval <<-RUBY, __FILE__, __LINE__
14
+ def #{key}
15
+ @geminus[#{key.inspect}]
16
+ end
17
+ RUBY
18
+ end
19
+
20
+ def generate_js
21
+ pairs = []
22
+
23
+ @geminus.each do |k, v|
24
+ v = v.is_a?(Container) ? v.generate_js : JSON.dump(v)
25
+ pairs << "#{JSON.dump k}:#{v}"
26
+ end
27
+
28
+ "{#{pairs.join ','}}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ function geminus(src, dst) {
2
+ var key, val;
3
+
4
+ dst = dst || world;
5
+
6
+ for (key in src) {
7
+ if (!src.hasOwnProperty(key)) {
8
+ continue;
9
+ }
10
+
11
+ val = src[key];
12
+
13
+ if (typeof val === "object") {
14
+ val = geminus(val, dst[key] || {});
15
+ }
16
+
17
+ Object.defineProperty(dst, key, {
18
+ configurable: true, // set to false once geminus() will not be redefining props
19
+ enumerable: true,
20
+ writable: false,
21
+ value: val
22
+ });
23
+ }
24
+
25
+ return dst;
26
+ }
@@ -0,0 +1,12 @@
1
+ require "delegate"
2
+ require "singleton"
3
+
4
+ module Geminus
5
+ class Registry < DelegateClass(Array)
6
+ include Singleton
7
+
8
+ def initialize
9
+ super([])
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Geminus
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geminus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexey V Zapparov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Simply share constants between backend/frontend.
70
+ email:
71
+ - ixti@member.fsf.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - geminus.gemspec
85
+ - lib/geminus.rb
86
+ - lib/geminus/container.rb
87
+ - lib/geminus/dsl.rb
88
+ - lib/geminus/preamble.js
89
+ - lib/geminus/registry.rb
90
+ - lib/geminus/version.rb
91
+ homepage: https://github.com/sensortower/geminus
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Simply share constants between backend/frontend.
115
+ test_files: []
116
+ has_rdoc: