archon 0.0.1 → 0.0.3
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 +4 -4
- data/.codeclimate.yml +19 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/README.md +3 -4
- data/Rakefile +6 -0
- data/archon.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dev.Dockerfile +11 -0
- data/docker-compose.yml +29 -0
- data/lib/archon.rb +25 -0
- data/lib/archon/insert_into_select.rb +41 -0
- data/lib/archon/nodes.rb +10 -0
- data/lib/archon/nodes/coalesce.rb +17 -0
- data/lib/archon/nodes/populated_recordset.rb +30 -0
- data/lib/archon/power_overwhelming.rb +34 -0
- data/lib/archon/version.rb +3 -0
- metadata +35 -2
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at weare@icalialabs.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
ARchon: Summoning the powers of ActiveRecord and ARel to wreak havoc
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
|
5
|
+
Archon is a collection of Arel nodes, shortcut methods and ActiveRecord model methods that make
|
|
6
|
+
doing complicated database queries & stuff simpler and right.
|
|
8
7
|
|
|
9
8
|
## Installation
|
|
10
9
|
|
|
@@ -34,7 +33,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
34
33
|
|
|
35
34
|
## Contributing
|
|
36
35
|
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/IcaliaLabs/archon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
38
37
|
|
|
39
38
|
|
|
40
39
|
## License
|
data/Rakefile
ADDED
data/archon.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'archon/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "archon"
|
|
8
|
+
spec.version = Archon::VERSION
|
|
9
|
+
spec.authors = ["Roberto Quintanilla"]
|
|
10
|
+
spec.email = ["vov@icalialabs.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{ARchon: Summoning the powers of ActiveRecord and ARel to wreak havoc}
|
|
13
|
+
spec.description = %q{A collection of methods and classes that unleash the power of the database :D}
|
|
14
|
+
spec.homepage = "https://github.com/IcaliaLabs/archon-gem"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
all_things_rails_version_string = ['>= 4.2']
|
|
25
|
+
spec.add_runtime_dependency %q<activerecord>, all_things_rails_version_string
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
|
30
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "archon"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dev.Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# 1: Use ruby 2.3.3 as base:
|
|
2
|
+
FROM ruby:2.3.3
|
|
3
|
+
|
|
4
|
+
# 2: We'll set this gem path as the working directory
|
|
5
|
+
WORKDIR /usr/src/lib
|
|
6
|
+
|
|
7
|
+
# 3: We'll set the working dir as HOME and add the app's binaries path to $PATH:
|
|
8
|
+
ENV HOME=/usr/src/lib PATH=/usr/src/lib/bin:$PATH
|
|
9
|
+
|
|
10
|
+
# 4: Set the default command:
|
|
11
|
+
CMD ["guard"]
|
data/docker-compose.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
version: '2.1'
|
|
2
|
+
|
|
3
|
+
volumes:
|
|
4
|
+
archon-gems:
|
|
5
|
+
driver: local
|
|
6
|
+
|
|
7
|
+
services:
|
|
8
|
+
|
|
9
|
+
lib:
|
|
10
|
+
build:
|
|
11
|
+
context: .
|
|
12
|
+
dockerfile: dev.Dockerfile
|
|
13
|
+
image: icalialabs/archon-gem:development
|
|
14
|
+
|
|
15
|
+
volumes:
|
|
16
|
+
# Mount our app code directory (".") into our app containers at the `/usr/src/lib` folder:
|
|
17
|
+
- .:/usr/src/lib
|
|
18
|
+
# Mount the 'archon-gems' volume on the folder that stores bundled gems:
|
|
19
|
+
- archon-gems:/usr/local/bundle
|
|
20
|
+
|
|
21
|
+
# Keep the stdin open, so we can attach to our app container's process
|
|
22
|
+
# and do things such as byebug, etc:
|
|
23
|
+
stdin_open: true
|
|
24
|
+
|
|
25
|
+
# Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
|
|
26
|
+
tty: true
|
|
27
|
+
|
|
28
|
+
# The command:
|
|
29
|
+
command: guard
|
data/lib/archon.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "archon/version"
|
|
2
|
+
|
|
3
|
+
# = Archon
|
|
4
|
+
#
|
|
5
|
+
# Archon is a collection of Arel nodes, shortcut methods and ActiveRecord model methods that make
|
|
6
|
+
# doing complicated stuff relatively simpler.
|
|
7
|
+
module Archon
|
|
8
|
+
extend ActiveSupport::Autoload
|
|
9
|
+
|
|
10
|
+
autoload :Nodes
|
|
11
|
+
autoload :InsertIntoSelect
|
|
12
|
+
autoload :PowerOverwhelming
|
|
13
|
+
|
|
14
|
+
def self.method_missing(called_method_name, *arguments, &block)
|
|
15
|
+
# Call super to raise a method missing error if no class was loaded:
|
|
16
|
+
called_method_name_as_constant = called_method_name.to_s.camelize
|
|
17
|
+
super unless [
|
|
18
|
+
"Archon::Nodes::#{called_method_name_as_constant}".safe_constantize,
|
|
19
|
+
"Archon::#{called_method_name_as_constant}".safe_constantize
|
|
20
|
+
].compact!.any?
|
|
21
|
+
|
|
22
|
+
# Try again, this time we expect the loaded module added the method to Archon:
|
|
23
|
+
send called_method_name, *arguments, &block
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# = Archon.insert_into_select
|
|
2
|
+
module Archon
|
|
3
|
+
def self.insert_into_select(insertion_table, selection, options = {})
|
|
4
|
+
return InsertIntoSelect.new insertion_table, selection, options
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# = InsertIntoSelect
|
|
8
|
+
#
|
|
9
|
+
# Extends an ARel InsertManager that will generate an `INSERT INTO (...) SELECT` query, which will
|
|
10
|
+
# insert data into the given table from the given selection - either an ARel SelectManager-ish, or
|
|
11
|
+
# an ActiveRecord::Relation.
|
|
12
|
+
#
|
|
13
|
+
# It will try to determine the columns that will be inserted from the projections specified in the
|
|
14
|
+
# given selection.
|
|
15
|
+
class InsertIntoSelect < Arel::InsertManager
|
|
16
|
+
attr_reader :projections
|
|
17
|
+
def initialize(tableish, selectish, options = {})
|
|
18
|
+
super()
|
|
19
|
+
self.into tableish.respond_to?(:arel_table) ? tableish.arel_table : tableish
|
|
20
|
+
self.select selectish.respond_to?(:arel) ? selectish.arel : selectish
|
|
21
|
+
|
|
22
|
+
# Fetch the insert columns from the options - default to the select column names interpolated
|
|
23
|
+
# into the inserted table:
|
|
24
|
+
self.columns.concat options.fetch(
|
|
25
|
+
:columns,
|
|
26
|
+
ast.select.projections.map do |projection|
|
|
27
|
+
column_name = if projection.is_a? Arel::Attributes::Attribute
|
|
28
|
+
projection.name
|
|
29
|
+
elsif projection.is_a? Arel::Nodes::As
|
|
30
|
+
projection.right.delete('"').to_sym
|
|
31
|
+
elsif projection.is_a? Arel::Nodes::NamedFunction
|
|
32
|
+
projection.alias.delete('"').to_sym
|
|
33
|
+
else
|
|
34
|
+
raise "Don't know how to..."
|
|
35
|
+
end
|
|
36
|
+
ast.relation[column_name]
|
|
37
|
+
end
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/archon/nodes.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# = Archon.coalesce
|
|
2
|
+
module Archon
|
|
3
|
+
def self.coalesce(*coalescees)
|
|
4
|
+
return Nodes::Coalesce.new(*coalescees)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module Nodes
|
|
8
|
+
# = Coalesce
|
|
9
|
+
#
|
|
10
|
+
# An Arel node that generates a 'COALESCE' statement
|
|
11
|
+
class Coalesce < Arel::Nodes::NamedFunction
|
|
12
|
+
def initialize(*coalescees)
|
|
13
|
+
super 'COALESCE', coalescees
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# = Archon.populated_recordset
|
|
2
|
+
module Archon
|
|
3
|
+
def self.populated_recordset(base, rows = [])
|
|
4
|
+
return Nodes::PopulatedRecordset.new base, rows
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module Nodes
|
|
8
|
+
# = PopulatedRecordset
|
|
9
|
+
#
|
|
10
|
+
# This ARel node creates a populated recordset from a JSON generated by the given ruby array of
|
|
11
|
+
# hashes.
|
|
12
|
+
class PopulatedRecordset < Arel::Nodes::NamedFunction
|
|
13
|
+
def initialize(base, rows = [])
|
|
14
|
+
raise ArgumentError, "rows is not an array" unless rows.is_a? Array
|
|
15
|
+
super 'json_populate_recordset', [
|
|
16
|
+
Arel::Nodes::SqlLiteral.new(base),
|
|
17
|
+
Arel::Nodes::Quoted.new(ActiveSupport::JSON.encode(rows))
|
|
18
|
+
]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def aliased_as(recordset_alias)
|
|
22
|
+
Arel::Nodes::TableAlias.new(self, recordset_alias)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def selectable
|
|
26
|
+
Arel::SelectManager.new self
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Archon
|
|
2
|
+
# = PowerOverwhelming
|
|
3
|
+
#
|
|
4
|
+
# Packs several powerful convenient methods for ActiveRecord models. You can add them like this:
|
|
5
|
+
#
|
|
6
|
+
# == ActiveRecord >= 5.x
|
|
7
|
+
# ```
|
|
8
|
+
# # app/models/application_record.rb
|
|
9
|
+
# class ApplicationRecord < ActiveRecord::Base
|
|
10
|
+
# self.abstract_class = true
|
|
11
|
+
# include Archon::PowerOverwhelming
|
|
12
|
+
# end
|
|
13
|
+
# ```
|
|
14
|
+
#
|
|
15
|
+
# == ActiveRecord >= 4.2.x, < 5.x
|
|
16
|
+
# ```
|
|
17
|
+
# # initializers/archon.rb
|
|
18
|
+
# ActiveRecord::Base.send :include, Archon::PowerOverwhelming
|
|
19
|
+
# ```
|
|
20
|
+
module PowerOverwhelming
|
|
21
|
+
extend ActiveSupport::Concern
|
|
22
|
+
|
|
23
|
+
# = Archon::PowerOverwhelming::ClassMethods
|
|
24
|
+
# Some methods applied to model classes and ActiveRecord::Relation objects
|
|
25
|
+
module ClassMethods
|
|
26
|
+
def create_from(selectish)
|
|
27
|
+
transaction do
|
|
28
|
+
timestamp = ActiveRecord::Base.connection.quoted_date(Time.now)
|
|
29
|
+
timestamp = Arel::Nodes::SqlLiteral.new("'#{timestamp}'")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: archon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roberto Quintanilla
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.2'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.2'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: bundler
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -60,9 +74,28 @@ executables: []
|
|
|
60
74
|
extensions: []
|
|
61
75
|
extra_rdoc_files: []
|
|
62
76
|
files:
|
|
77
|
+
- ".codeclimate.yml"
|
|
63
78
|
- ".gitignore"
|
|
79
|
+
- ".rspec"
|
|
80
|
+
- ".rubocop.yml"
|
|
81
|
+
- ".travis.yml"
|
|
82
|
+
- CODE_OF_CONDUCT.md
|
|
83
|
+
- Gemfile
|
|
64
84
|
- LICENSE
|
|
65
85
|
- README.md
|
|
86
|
+
- Rakefile
|
|
87
|
+
- archon.gemspec
|
|
88
|
+
- bin/console
|
|
89
|
+
- bin/setup
|
|
90
|
+
- dev.Dockerfile
|
|
91
|
+
- docker-compose.yml
|
|
92
|
+
- lib/archon.rb
|
|
93
|
+
- lib/archon/insert_into_select.rb
|
|
94
|
+
- lib/archon/nodes.rb
|
|
95
|
+
- lib/archon/nodes/coalesce.rb
|
|
96
|
+
- lib/archon/nodes/populated_recordset.rb
|
|
97
|
+
- lib/archon/power_overwhelming.rb
|
|
98
|
+
- lib/archon/version.rb
|
|
66
99
|
homepage: https://github.com/IcaliaLabs/archon-gem
|
|
67
100
|
licenses:
|
|
68
101
|
- MIT
|