Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new subcards api and list/listed_by relations #513

Merged
merged 61 commits into from Oct 9, 2015
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a0386f0
list and listed_by cardtypes
xithan Jul 15, 2015
4de490a
Merge remote-tracking branch 'upstream/master' into listedby
xithan Sep 16, 2015
024a3d5
refactoring subcards
xithan Sep 21, 2015
fb0d1c5
.codeclimate.yml: ingnore assets
xithan Sep 22, 2015
1aa90c8
subcards overhaul
xithan Sep 23, 2015
b0aacba
getting closer to get subcards working
xithan Sep 26, 2015
a043770
correct type count test
xithan Sep 28, 2015
9680251
fetch.rb: refactor #fetch_from_cache_or_db
xithan Sep 28, 2015
ed661f1
let subcards survive #expire
xithan Sep 28, 2015
14c54c5
Merge remote-tracking branch 'wagn/master' into listedby
xithan Sep 29, 2015
34b48eb
.ruby-style.yml: require no parens for method definitions
xithan Sep 29, 2015
9f64fc3
can almost see the green light
xithan Sep 29, 2015
07b2d51
seed tick
xithan Sep 29, 2015
6d3957c
:checkered_flag:
xithan Sep 29, 2015
aac4d61
remove unused #given_name
xithan Sep 29, 2015
66f7bd1
restore wagn logo
xithan Sep 29, 2015
f6ecbe0
houndiness
xithan Sep 29, 2015
54b4c24
check if the listed_by relation makes it to the reference table
xithan Sep 30, 2015
7c5db75
add rubocop config file
xithan Sep 30, 2015
495f156
.ruby-style.yml: leading dot position for multi-line method calls
xithan Sep 30, 2015
d38553d
:dog2:
xithan Sep 30, 2015
08f2c27
:dog2::dog2:
xithan Sep 30, 2015
35dcc67
get features passing
xithan Oct 1, 2015
153c8bd
Merge remote-tracking branch 'wagn/master' into listedby
xithan Oct 1, 2015
aa5df6a
refactor card initialization
xithan Oct 5, 2015
ce2be16
refactor #fetch
xithan Oct 5, 2015
65a274b
machine.rb: update after :expire_related instead of after :store_subc…
xithan Oct 5, 2015
25cc8c1
phase.rb: preparations for phase methods
xithan Oct 5, 2015
3d68e08
move specs from type_spec to initialize_spec
xithan Oct 5, 2015
b83120e
specs clean up
xithan Oct 5, 2015
cf1d443
wagn.rake: update deprecated constant
xithan Oct 5, 2015
8982834
search_type.rb bug: invalid default type if WQL doesn't search for a …
xithan Oct 5, 2015
8e877a5
set.rb: more phase methods
xithan Oct 5, 2015
923f6e3
name.rb: #to_sym for name objects
xithan Oct 5, 2015
d6bc67c
houndiness
xithan Oct 5, 2015
7ad511c
all/subcards.rb: move subcard methods from phases.rb here
xithan Oct 5, 2015
15ccd61
subcards.rb: use local cache only
xithan Oct 5, 2015
b48d200
more houndiness
xithan Oct 5, 2015
2c5d5dd
fetch.rb#fetch_id: treat only symbols as codenames
xithan Oct 6, 2015
12a5142
auth.rb: refactor #needs_setup?
xithan Oct 6, 2015
61900fd
subcards.rb: rename :filter_empty_subcards to :reject_empty_subcards
xithan Oct 6, 2015
847ca40
subcards.rb: renamed #empty? to #unfilled?
xithan Oct 6, 2015
0638ed6
add method for creating active accounts
xithan Oct 6, 2015
06eaf92
subcards.rb: fix for subsubcards
xithan Oct 6, 2015
671ce92
renamed list.rb
xithan Oct 6, 2015
e11bd4c
form.rb: introduce form_root
xithan Oct 6, 2015
9d3ebaa
final(?) adjustments
xithan Oct 6, 2015
79d3208
hound style updates
xithan Oct 6, 2015
1cec401
seed update
xithan Oct 6, 2015
3ec0850
Merge remote-tracking branch 'wagn/master' into listedby
xithan Oct 6, 2015
b1d53b5
hound
xithan Oct 6, 2015
6f66c3a
:dog:
xithan Oct 6, 2015
3a486e7
ruby-style: turn "unnecessary spacing" off
xithan Oct 7, 2015
66977a5
:dog:
xithan Oct 7, 2015
4a2b2b0
fixed phase_method API
xithan Oct 7, 2015
4590c7b
:dog:
xithan Oct 7, 2015
6eeb5b2
another phase_method fix
xithan Oct 7, 2015
69c51cb
:dog:
xithan Oct 7, 2015
5d1b178
fetch.rb: refactor #fetch
xithan Oct 7, 2015
d7bd5c5
phase fixes
xithan Oct 7, 2015
e676aac
lock selenium-webdriver gem to 2.47
xithan Oct 8, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .codeclimate.yml
@@ -0,0 +1,7 @@
languages:
Ruby: true
JavaScript: true
PHP: false
Python: false
exclude_paths:
- "wagn/rails/assets"
2 changes: 1 addition & 1 deletion .ruby-style.yml
Expand Up @@ -250,7 +250,7 @@ Style/MethodDefParentheses:
Description: Checks if the method definitions have or don't have parentheses.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens
Enabled: true
EnforcedStyle: require_parentheses
EnforcedStyle: require_no_parentheses
SupportedStyles:
- require_parentheses
- require_no_parentheses
Expand Down
13 changes: 13 additions & 0 deletions card/db/migrate_core_cards/20150708224756_add_list_cards.rb
@@ -0,0 +1,13 @@
# -*- encoding : utf-8 -*-

class AddListCards < Card::CoreMigration
def up
Card.create! :name=>'List', :type_code=>:cardtype, :codename=>:list
Card.create! :name=>'Listed by', :type_code=>:cardtype, :codename=>:listed_by,
:subcards=>{'+*right+*structure'=>'{{+type}}{{+list name}}'}
Card.create! :name=>'*cached count', :codename=>:cached_count,
:subcards=>{'+*right+*update'=>'[[Administrator]]', '+*right+*create'=>'[[Administrator]]', '+*right+*delete'=>'[[Administrator]]'}
Card.create! :name=>'*cached content', :codename=>:cached_content,
:subcards=>{'+*right+*update'=>'[[Administrator]]', '+*right+*create'=>'[[Administrator]]', '+*right+*delete'=>'[[Administrator]]'}
end
end
2 changes: 1 addition & 1 deletion card/db/seed
Submodule seed updated from be14cb to 5bf095
3 changes: 2 additions & 1 deletion card/lib/card.rb
Expand Up @@ -32,6 +32,7 @@ def self.serializable_attr_accessor *args
require_dependency 'card/act'
require_dependency 'card/change'
require_dependency 'card/reference'
require_dependency 'card/subcards'
require_dependency 'card/view_cache'

has_many :references_from, class_name: :Reference, foreign_key: :referee_id
Expand All @@ -43,7 +44,7 @@ def self.serializable_attr_accessor *args
cattr_accessor :set_patterns, :error_codes, :serializable_attributes, :set_specific_attributes
@@set_patterns, @@error_codes = [], {}

serializable_attr_accessor :action, :supercard, :current_act, :current_action,
serializable_attr_accessor :action, :supercard, :superleft, :current_act, :current_action,
:comment, :comment_author, # obviated soon
:update_referencers, # wrong mechanism for this
:update_all_users, # if the above is wrong then this one too
Expand Down
2 changes: 1 addition & 1 deletion card/lib/card/cache.rb
Expand Up @@ -211,7 +211,7 @@ def reset_local
end

def exist? key
@local.has_key?(key) || @store.exist?(key)
@local.has_key?(key) || (@store && @store.exist?(key))
end
end
end
Expand Down
28 changes: 25 additions & 3 deletions card/lib/card/name.rb
Expand Up @@ -38,17 +38,39 @@ def trait tag_code
name ? name.s : ( raise Card::NotFound, "unknown codename: #{tag_code}" )
end

def field tag_name
field_name( tag_name).s
end

def code
Card::Codename[ Card.fetch_id self ]
end

def field_name tag_name
case tag_name
when Symbol
trait_name tag_name
else
[ self, tag_name ].to_name
end
end

def relative_field_name tag_name
field_name(tag_name).relative_name(self)
end

def relative_name context_name
self.to_show(*context_name.to_name.parts).to_name
end

def absolute_name context_name
self.to_absolute_name(context_name)
end

def is_a_field_of? context_name
if context_name.present?
# Do I still equal myself after I've been relativised in the context of context_name?
relative_name = self.to_show(*context_name.to_name.parts).to_name
absolute_name = self.to_absolute_name(context_name)
relative_name.key != absolute_name.key
relative_name(context_name).key != absolute_name(context_name).key
else
self.s.match /^\s*\+/
end
Expand Down
3 changes: 1 addition & 2 deletions card/lib/card/set.rb
Expand Up @@ -432,8 +432,7 @@ def define_trait_reader trait
def define_trait_writer trait
define_method "#{trait}=" do |value|
card = send "#{trait}_card"
self.subcards ||= {}
self.subcards[card.name] = {type_id: card.type_id, content: value }
subcards.add :name=>card.name, type_id: card.type_id, content: value
instance_variable_set "@#{trait}", value
end
end
Expand Down
236 changes: 236 additions & 0 deletions card/lib/card/subcards.rb
@@ -0,0 +1,236 @@
# -*- encoding : utf-8 -*-

# API to create/update/delete additional cards together with the main card.
# The most common case is for fields. For example toghether with "my address" you want to create the subcards "my address+name", "my address+street", etc. but subcards don't have to be descendants.

# Subcards can be added as card objects or attribute hashes.



class Card
def subcards
@subcards ||= Subcards.new(self)
end

def field tag
Card[cardname.field(tag)]
end

def subcard card_name
subcards.card card_name
end

def subfield field_name
subcards.field field_name
end

def add_subcard name_or_card, args=nil
subcards.add name_or_card, args
end

def add_subfield name, args=nil
subcards.add_field name, args
end

def remove_subcard name_or_card
subcards.remove name_or_card
end

def remove_subfield name_or_card
subcards.remove_field name_or_card
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above the new subcards API


def preserve_subcards
if subcards.present?
Card::Cache[Card::Subcards].write key, @subcards
end
end

def restore_subcards
if Card::Cache[Card::Subcards].exist? key
@subcards = Card::Cache[Card::Subcards].fetch key
end
end

def expire_subcards
Card::Cache[Card::Subcards].delete key
end


class Subcards

def initialize(context_card)
@context_card = context_card
@keys = ::Set.new
end

def remove name_or_card
key = case name_or_card
when Card
name_or_card.key
when Symbol
fetch_subcard(name_or_card).key
else
name_or_card.to_name.key
end

@keys.include? key && @keys.delete(key)
end

def add name_or_card_or_attr, card_or_attr=nil
if card_or_attr
name = name_or_card_or_attr
else
card_or_attr = name_or_card_or_attr
end
case card_or_attr
when Hash
args = card_or_attr
if name
add_attributes name, args
elsif args[:name]
add_attributes args.delete(:name), args
else
args.each_pair do |key, val|
if val.kind_of? String
add_attributes key, :content => val
else
add_attributes key, val
end
end
end
when Card
add_card card_or_attr
when Symbol, String
add_attributes card_or_attr, {}
end
end

def << value
add value
end

def method_missing method, *args
if @keys.respond_to? method
@keys.send method, *args
end
end


def each_card
@keys.each do |key|
yield(fetch_subcard key)
end
end

alias_method :each, :each_card

def each_with_key
@keys.each do |key|
yield(fetch_subcard(key), key)
end
end

def []= name, card_or_attr
case card_or_attr
when Hash
add_attributes name, card_or_attr
when Card
add_card name, card_or_attr
end
end

def [] name
card name
end

def field name
key = field_name_to_key name
if @keys.include? key
fetch_subcard key
end
end

def card name
if @keys.include? name.to_name.key
fetch_subcard name
end
end

def add_child name, args
add prepend_plus(name), args
end

def remove_child name_or_card
if name_or_card.kind_of? Card
remove name_or_card
else
absolute_name = @context_card.cardname.field_name(name_or_card)
if @keys.include? absolute_name.key
remove absolute_name
else
remove @context_card.cardname.relative_field_name(name_or_card)
end
end
end

alias_method :add_field, :add_child
alias_method :remove_field, :remove_child

def present?
@keys.present?
end

private

def fetch_subcard key
Card.fetch key, :subcard => true
end


def prepend_plus name
case name
when Symbol
"+#{Card[name].name}"
when /^\+/
name
else
"+#{name}"
end
end

def field_name_to_key name
if @context_card.name =~ /^\+/
@context_card.cardname.relative_field_name(name).key
else
absolute_key = @context_card.cardname.field_name(name).key
if @keys.include? absolute_key
absolute_key
else
@context_card.cardname.relative_field_name(name).key
end
end
end

def add_attributes name, attributes={}
absolute_name =
if @context_card.name =~ /^\+/
name
else
name.to_name.to_absolute_name(@context_card.name).s
end
card = Card.assign_or_initialize_by absolute_name, attributes
add_card card
end

def add_card card
card.supercard = @context_card
if !card.cardname.simple? && card.cardname.is_a_field_of?(@context_card.cardname)
card.superleft = @context_card
end
@keys << card.key
Card.write_to_cache card
card
end
end
end