Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switch to Fancy::Package::Specification

  • Loading branch information...
commit e24b551d9a10ea9b89cc9a40046421b0fb7ccbb5 1 parent 4371db2
@bakkdoor bakkdoor authored
View
41 lib/fancy/package/dependency.fy
@@ -0,0 +1,41 @@
+class Fancy Package Dependency {
+ def self from_json: json {
+ if: json then: {
+ new from_json: $ JSON parse: json
+ }
+ }
+
+
+ def for_json {
+ @{
+ name: @name
+ version: @version
+ }
+ }
+
+ def from_json: json {
+ @name, @version = json values_at: ("name", "version")
+ self
+ }
+}
+
+class Fancy Package RubyDependency {
+ def self from_json: json {
+ if: json then: {
+ new from_json: $ JSON parse: json
+ }
+ }
+
+
+ def for_json {
+ @{
+ gem_name: @gem_name
+ version: @version
+ }
+ }
+
+ def from_json: json {
+ @gem_name, @version = json values_at: ("gem_name", "version")
+ self
+ }
+}
View
51 lib/fancy/package/specification.fy
@@ -0,0 +1,51 @@
+class Fancy Package Specification {
+ def initialize: block {
+ @include_files = []
+ @bin_files = []
+ @dependencies = []
+ @ruby_dependencies = []
+
+ block call: [self]
+ }
+
+ def self from_json: json {
+ if: json then: {
+ new from_json: $ JSON parse: json
+ }
+ }
+
+ def for_json {
+ @{
+ author: @author
+ email: @email
+ include_files: @include_files
+ bin_files: @bin_files
+ description: @description
+ homepage: @homepage
+ version: @version
+ gh_user: @gh_user
+ package_name: @package_name
+ dependencies: $ @dependencies map: @{ for_json }
+ ruby_dependencies: $ @ruby_dependencies map: @{ for_json }
+ }
+ }
+
+ def from_json: json {
+ @author, @email, @include_files, @bin_files, \
+ @description, @homepage, @version, @gh_user, \
+ @package_name, @dependencies, @ruby_dependencies = \
+ json values_at: ("author", "email", "include_files", "bin_files", \
+ "description", "homepage", "version", "gh_user", \
+ "package_name", "dependencies", "ruby_dependencies")
+
+ @include_files = @include_files to_a
+ @bin_files = @bin_files to_a
+ @dependencies = @dependencies to_a
+ @ruby_dependencies = @ruby_dependencies to_a
+ self
+ }
+
+ def repo_url {
+ "https://github.com/#{@gh_user}/#{@package_name}"
+ }
+}
View
4 lib/fpr.fy
@@ -3,9 +3,11 @@ class FPR
require: "sinatra.fy"
require: "redis.fy"
+require: "fancy/package/specification"
+require: "fancy/package/dependency"
+
require: "fpr/json"
require: "fpr/api_helpers"
-require: "fpr/package"
require: "fpr/packages"
class FPR {
View
37 lib/fpr/package.fy
@@ -1,37 +0,0 @@
-class FPR {
- class Package {
-
- def Package from_json: json {
- if: json then: {
- Package new from_json: $ JSON parse: json
- }
- }
-
- read_write_slots: ('repo_url, 'name, 'version, 'description, 'dependencies, 'ruby_dependencies, 'author, 'email)
- def initialize: block {
- @dependencies = []
- @ruby_dependencies = []
- block call: [self]
- }
-
- def for_json {
- @{
- name: @name
- version: @version
- description: @description
- dependencies: @dependencies
- ruby_dependencies: @ruby_dependencies
- repo_url: @repo_url
- author: @author
- email: @email
- }
- }
-
- def from_json: json {
- @name, @version, @description, @dependencies, @ruby_dependencies, @author, @email, @repo_url = json values_at: ("name", "version", "description", "dependencies", "ruby_dependencies", "author", "email", "repo_url")
- @dependencies = @dependencies to_a
- @ruby_dependencies = @ruby_dependencies to_a
- self
- }
- }
-}
View
22 lib/fpr/packages.fy
@@ -36,7 +36,7 @@ class FPR {
with_redis: {
package_names . map: |name| {
keys = *redis* keys: "package:#{name}:*" . map: |key| {
- Package from_json: $ *redis* get: key
+ Fancy Package Specification from_json: $ *redis* get: key
} . compact
} . flatten
}
@@ -49,7 +49,7 @@ class FPR {
def package: package_name version: version ('latest) {
with_redis: {
json = *redis* get: $ key: package_name version: version
- Package from_json: json
+ Fancy Package Specification from_json: json
}
}
@@ -71,24 +71,16 @@ class FPR {
}
content = Base64 decode64(json["content"])
- spec = content eval
- package = Package new: @{
- name: $ spec package_name
- version: $ spec version
- description: $ spec description
- dependencies: $ spec dependencies
- ruby_dependencies: $ spec ruby_dependencies
- repo_url: "https://github.com/#{package_name}"
- author: $ spec author
- email: $ spec email
- }
+ package_spec = content eval
+ package_spec package_name: repo_name
+ package_spec gh_user: repo_user
with_redis: {
*redis* sadd: ('package_names, "#{package_name}")
- *redis* set: ("package:#{package_name}:#{package version}", package for_json to_json)
+ *redis* set: ("package:#{package_name}:#{package_spec version}", package_spec for_json to_json)
}
- package
+ package_spec
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.